Skip to content

Commit d9147e0

Browse files
committed
Ignore transitive errors in multiple inheritance
1 parent e067603 commit d9147e0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

mypy/checker.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,9 +2841,19 @@ class C(B, A[int]): ... # this is unsafe because...
28412841
and ctx.mro.index(b1type) > ctx.mro.index(b2type)
28422842
):
28432843
b1type, b2type = b2type, b1type
2844+
base1, base2 = base2, base1
28442845
first_type, second_type = second_type, first_type
28452846
first_node, second_node = second_node, first_node
28462847

2848+
if (
2849+
base1 is not None
2850+
and base2 is not None
2851+
and is_subtype(base1, base2, ignore_promotions=True)
2852+
):
2853+
# If base1 already inherits from base2 with correct type args,
2854+
# we have reported errors if any. Avoid reporting them again.
2855+
return
2856+
28472857
# TODO: use more principled logic to decide is_subtype() vs is_equivalent().
28482858
# We should rely on mutability of superclass node, not on types being Callable.
28492859

test-data/unit/check-generic-subtyping.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,3 +1090,14 @@ class C5(A2[U], B[T]): pass # E: Definition of "x" in base class "A" is incompa
10901090
# E: Definition of "fn" in base class "A" is incompatible with definition in base class "B"
10911091

10921092
[builtins fixtures/tuple.pyi]
1093+
1094+
[case testMultipleInheritanceCompatErrorPropagation]
1095+
class A:
1096+
foo: bytes
1097+
class B(A):
1098+
foo: str # type: ignore[assignment]
1099+
1100+
class Ok(B, A): pass
1101+
1102+
class C(A): pass
1103+
class Ok2(B, C): pass

0 commit comments

Comments
 (0)