Skip to content

Commit 289f7f0

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 88fd8fd commit 289f7f0

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
@@ -1985,6 +1985,10 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
19851985
for parent_cls in mro.ancestors_no_object().iter() {
19861986
let class_fields = parent_cls.class_object().fields();
19871987
for field in class_fields {
1988+
// Skip fields that are not relevant for override consistency checks
1989+
if !self.should_check_field_for_override_consistency(field) {
1990+
continue
1991+
}
19881992
let key = KeyClassField(parent_cls.class_object().index(), field.clone());
19891993
let field_entry = self.get_from_class(cls, &key);
19901994
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)