Skip to content
Open
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
12 changes: 12 additions & 0 deletions pyrefly/lib/alt/class/class_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3062,6 +3062,18 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
&want_class_field,
&Instance::of_protocol(parent, self.instantiate(cls)),
);
// If parent return type was inferred as Never (for example a method that only raises),
// skip override consistency checks so we preserve reachability behavior without
// producing noisy bad-override diagnostics.
if !want_class_field.has_explicit_annotation()
&& want_attribute
.clone()
.as_instance_method()
.and_then(|ty| ty.callable_return_type(self.heap))
.is_some_and(|ret| ret.is_never())
{
continue;
}
if got_attribute.is_none() {
// Optimisation: Only compute the `got_attr` once, and only if we actually need it.
got_attribute = Some(self.as_instance_attribute(
Expand Down
34 changes: 34 additions & 0 deletions pyrefly/lib/test/abstract_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,40 @@ class B(A):
"#,
);

testcase!(
test_abstract_method_non_abc,
r#"
from abc import abstractmethod

class A:
@abstractmethod
def foo(self):
raise NotImplementedError()

class B(A):
def foo(self):
x = 1
print(x)
"#,
);

testcase!(
test_raise_not_implemented_infers_never_but_allows_override,
r#"
from typing import Never, assert_type

class A:
def foo(self):
raise NotImplementedError()

assert_type(A().foo(), Never)

class B(A):
def foo(self) -> int:
return 1
"#,
);

testcase!(
test_abstract_method_abc_transitive,
r#"
Expand Down