8000 Do not ignore generic type args when checking multiple inheritance compatibility by sterliakov · Pull Request #18270 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Do not ignore generic type args when checking multiple inheritance compatibility #18270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Prev Previous commit
Next Next commit
Ignore transitive errors in multiple inheritance
  • Loading branch information
sterliakov committed Dec 9, 2024
commit d9147e06de8bf4b5f7de1eb337f114c61319ce13
10 changes: 10 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2841,9 +2841,19 @@ class C(B, A[int]): ... # this is unsafe because...
and ctx.mro.index(b1type) > ctx.mro.index(b2type)
):
b1type, b2type = b2type, b1type
base1, base2 = base2, base1
first_type, second_type = second_type, first_type
first_node, second_node = second_node, first_node

if (
base1 is not None
and base2 is not None
and is_subtype(base1, base2, ignore_promotions=True)
):
# If base1 already inherits from base2 with correct type args,
# we have reported errors if any. Avoid reporting them again.
return

# TODO: use more principled logic to decide is_subtype() vs is_equivalent().
# We should rely on mutability of superclass node, not on types being Callable.

Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-generic-subtyping.test
Original file line number Diff line number Diff line change
Expand Up @@ -1090,3 +1090,14 @@ class C5(A2[U], B[T]): pass # E: Definition of "x" in base class "A" is incompa
# E: Definition of "fn" in base class "A" is incompatible with definition in base class "B"

[builtins fixtures/tuple.pyi]

[case testMultipleInheritanceCompatErrorPropagation]
class A:
foo: bytes
class B(A):
foo: str # type: ignore[assignment]

class Ok(B, A): pass

class C(A): pass
class Ok2(B, C): pass
0