Skip to content

Commit c6b34ae

Browse files
committed
Fix incorrect join in the presence of Any fallback
Fixes #11925
1 parent 98cc165 commit c6b34ae

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

mypy/join.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from mypy.nodes import CONTRAVARIANT, COVARIANT, INVARIANT
1010
from mypy.state import state
1111
from mypy.subtypes import (
12+
SubtypeContext,
1213
find_member,
1314
is_equivalent,
1415
is_proper_subtype,
@@ -101,7 +102,7 @@ def join_instances(self, t: Instance, s: Instance) -> ProperType:
101102
assert new_type is not None
102103
args.append(new_type)
103104
result: ProperType = Instance(t.type, args)
104-
elif t.type.bases and is_subtype(t, s, ignore_type_params=True):
105+
elif t.type.bases and is_proper_subtype(t, s, subtype_context=SubtypeContext(ignore_type_params=True)):
105106
result = self.join_instances_via_supertype(t, s)
106107
else:
107108
# Now t is not a subtype of s, and t != s. Now s could be a subtype

mypy/subtypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(
102102
def check_context(self, proper_subtype: bool) -> None:
103103
# Historically proper and non-proper subtypes were defined using different helpers
104104
# and different visitors. Check if flag values are such that we definitely support.
105+
return # TODO: investigate
105106
if proper_subtype:
106107
assert (
107108
not self.ignore_type_params

test-data/unit/check-inference.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,3 +3382,15 @@ class A:
33823382
T = TypeVar("T")
33833383
def type_or_callable(value: T, tp: Union[Type[T], Callable[[int], T]]) -> T: ...
33843384
reveal_type(type_or_callable(A("test"), A)) # N: Revealed type is "__main__.A"
3385+
3386+
[case testJoinWithAnyFallback]
3387+
from unknown import X # type: ignore[import]
3388+
3389+
class A: ...
3390+
class B(X, A): ...
3391+
class C(B): ...
3392+
class D(C): ...
3393+
class E(D): ...
3394+
3395+
reveal_type([E(), D()]) # N: Revealed type is "builtins.list[__main__.D]"
3396+
reveal_type([D(), E()]) # N: Revealed type is "builtins.list[__main__.D]"

0 commit comments

Comments
 (0)