Skip to content

Commit b290fd1

Browse files
committed
Skip multiple inheritance checks for "special" fields
We're skipping them for the override checks already. Re-using the refactored function to also skip them during multiple inheritance checks. Newly added test is passing because we don't check methods in multiple inheritance checks yet. Adding the test there to prevent regressions.
1 parent badc31d commit b290fd1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pyrefly/lib/alt/class/class_field.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,10 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
19821982
for parent_cls in mro.ancestors_no_object().iter() {
19831983
let class_fields = parent_cls.class_object().fields();
19841984
for field in class_fields {
1985+
// Skip fields that are not relevant for override consistency checks
1986+
if !self.should_check_field_for_override_consistency(field) {
1987+
continue;
1988+
}
19851989
let key = KeyClassField(parent_cls.class_object().index(), field.clone());
19861990
let field_entry = self.get_from_class(cls, &key);
19871991
if let Some(field_entry) = field_entry.as_ref() {

pyrefly/lib/test/class_subtyping.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,16 @@ class Both(Foo, Bar): # Expect error here
324324
...
325325
"#,
326326
);
327+
328+
testcase!(
329+
test_multiple_inheritance_special_methods,
330+
r#"
331+
class Foo:
332+
def __init__(self, x: int) -> None: ...
333+
class Bar:
334+
def __init__(self, x: str) -> None: ...
335+
336+
class Both(Foo, Bar): # No error here, because __init__ is special
337+
...
338+
"#,
339+
);

0 commit comments

Comments
 (0)