Skip to content

Commit 46ec61b

Browse files
committed
Place inheritance check earlier
1 parent 1960ad9 commit 46ec61b

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

mypy/checker.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,9 +2809,16 @@ class C(B, A[int]): ... # this is unsafe because...
28092809
if name in ("__init__", "__new__", "__init_subclass__"):
28102810
# __init__ and friends can be incompatible -- it's a special case.
28112811
return
2812+
2813+
if is_subtype(base1, base2, ignore_promotions=True):
2814+
# If base1 already inherits from base2 with correct type args,
2815+
# we have reported errors if any. Avoid reporting them again.
2816+
return
2817+
28122818
first_type = first_node = None
28132819
second_type = second_node = None
28142820
orig_var = ctx.get(name)
2821+
28152822
if orig_var is not None and orig_var.node is not None:
28162823
if (b1type := base1.type.get_containing_type_info(name)) is not None:
28172824
base1 = map_instance_to_supertype(base1, b1type)
@@ -2846,15 +2853,6 @@ class C(B, A[int]): ... # this is unsafe because...
28462853
first_type, second_type = second_type, first_type
28472854
first_node, second_node = second_node, first_node
28482855

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

0 commit comments

Comments
 (0)