WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions conformance/third_party/conformance.exp
Original file line number Diff line number Diff line change
Expand Up @@ -8778,6 +8778,17 @@
"stop_column": 20,
"stop_line": 60
},
{
"code": -2,
"column": 15,
"concise_description": "Cannot instantiate `Concrete1` because the following members are abstract: `cm1`",
"description": "Cannot instantiate `Concrete1` because the following members are abstract: `cm1`",
"line": 89,
"name": "bad-instantiation",
"severity": "error",
"stop_column": 17,
"stop_line": 89
},
{
"code": -2,
"column": 15,
Expand Down
4 changes: 1 addition & 3 deletions conformance/third_party/conformance.result
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@
"Line 117: Expected 1 errors",
"Line 79: Unexpected errors ['`Concrete` is not assignable to `Template`\\n Protocol `Template` requires attribute `temp`']"
],
"protocols_explicit.py": [
"Line 89: Expected 1 errors"
],
"protocols_explicit.py": [],
"protocols_generic.py": [],
"protocols_merging.py": [],
"protocols_modules.py": [
Expand Down
8 changes: 4 additions & 4 deletions conformance/third_party/results.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"total": 138,
"pass": 103,
"fail": 35,
"pass": 104,
"fail": 34,
"pass_rate": 0.75,
"differences": 146,
"differences": 145,
"passing": [
"aliases_explicit.py",
"aliases_newtype.py",
Expand Down Expand Up @@ -81,6 +81,7 @@
"overloads_consistency.py",
"overloads_definitions.py",
"overloads_evaluation.py",
"protocols_explicit.py",
"protocols_generic.py",
"protocols_merging.py",
"protocols_recursive.py",
Expand Down Expand Up @@ -138,7 +139,6 @@
"literals_interactions.py": 2,
"protocols_class_objects.py": 4,
"protocols_definition.py": 3,
"protocols_explicit.py": 1,
"protocols_modules.py": 1,
"protocols_variance.py": 7,
"qualifiers_annotated.py": 6,
Expand Down
21 changes: 21 additions & 0 deletions pyrefly/lib/alt/class/class_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,27 @@ impl ClassField {
}
}

pub fn is_uninit_class_var(&self) -> bool {
match &self.0 {
ClassFieldInner::Property { .. } => false,
ClassFieldInner::Descriptor { .. } => false,
ClassFieldInner::Method { .. } => false,
ClassFieldInner::NestedClass { .. } => false,
ClassFieldInner::ClassAttribute {
is_classvar,
initialization,
..
} => {
*is_classvar
&& matches!(
initialization,
ClassFieldInitialization::Uninitialized | ClassFieldInitialization::Magic
)
}
ClassFieldInner::InstanceAttribute { .. } => false,
}
}

pub fn is_init_var(&self) -> bool {
match &self.0 {
ClassFieldInner::Property { .. } => false,
Expand Down
5 changes: 4 additions & 1 deletion pyrefly/lib/alt/class/class_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,10 +1209,13 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
.cloned(),
);
}

let mut abstract_members = SmallSet::new();
for field_name in fields_to_check {
if let Some(field) = self.get_non_synthesized_class_member(cls, &field_name)
&& field.is_abstract()
&& (field.is_abstract() ||
// If a class variable is declared on the interface file, don't consider as abstract
!cls.module().path().is_interface() && field.is_uninit_class_var())
{
abstract_members.insert(field_name.clone());
}
Expand Down
12 changes: 12 additions & 0 deletions pyrefly/lib/test/abstract_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,15 @@ class D(C): # E: Class `D` has unimplemented abstract members: `bar`
yield 1
"#,
);

testcase!(
test_uninit_classvar_abc,
r#"
from abc import ABC
from typing import ClassVar, final
@final
class A(ABC): # E: Final class `A` cannot have unimplemented abstract members: `x`
x: ClassVar[int]
a = A() # E: Cannot instantiate `A` because the following members are abstract: `x`
"#,
);
15 changes: 15 additions & 0 deletions pyrefly/lib/test/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,18 @@ isinstance(Impl(), GenericProtocol) # E: Runtime checkable protocol `GenericPro
issubclass(Impl, GenericProtocol) # E: Runtime checkable protocol `GenericProtocol` has an unsafe overlap with type `Impl`
"#,
);

testcase!(
test_protocol_with_uninit_classvar,
r#"
from typing import Protocol, ClassVar, final
class P(Protocol):
x: ClassVar[int]

@final
class C(P): # E: Final class `C` cannot have unimplemented abstract members: `x`
pass

c = C() # E: Cannot instantiate `C` because the following members are abstract: `x`
"#,
);