Skip to content

Commit 2d7d305

Browse files
committed
Handle unbound type
1 parent 53b168b commit 2d7d305

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

mypy/meet.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
UninhabitedType, TypeType, TypeOfAny, Overloaded, FunctionLike, LiteralType,
88
ProperType, get_proper_type, get_proper_types, TypeAliasType, TypeGuardType
99
)
10+
from mypy.sametypes import is_same_type
1011
from mypy.subtypes import is_equivalent, is_subtype, is_callable_compatible, is_proper_subtype
1112
from mypy.erasetype import erase_type
1213
from mypy.maptype import map_instance_to_supertype
@@ -45,6 +46,8 @@ def meet_types(s: Type, t: Type) -> ProperType:
4546
return t
4647
if isinstance(s, UnionType) and not isinstance(t, UnionType):
4748
s, t = t, s
49+
if isinstance(s, TypeVarType) and not isinstance(t, TypeVarType):
50+
s, t = t, s
4851
return t.accept(TypeMeetVisitor(s))
4952

5053

@@ -483,7 +486,8 @@ def visit_erased_type(self, t: ErasedType) -> ProperType:
483486
def visit_type_var(self, t: TypeVarType) -> ProperType:
484487
if isinstance(self.s, TypeVarType) and self.s.id == t.id:
485488
return self.s
486-
elif is_subtype(get_proper_type(t.upper_bound), self.s):
489+
elif (not isinstance(self.s, UnboundType) and
490+
is_same_type(t.upper_bound, meet_types(t.upper_bound, self.s))):
487491
return t
488492
else:
489493
return self.default(self.s)

mypy/test/testtypes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,11 @@ def test_type_vars(self) -> None:
895895
self.assert_meet(self.fx.s, self.fx.s, self.fx.s)
896896
self.assert_meet(self.fx.t, self.fx.s, NoneType())
897897

898+
def test_type_vars_bound(self) -> None:
899+
self.assert_meet(self.fx.t, self.fx.o, self.fx.t)
900+
self.assert_meet(self.fx.o, self.fx.t, self.fx.t)
901+
self.assert_meet(self.fx.t, self.fx.a, NoneType())
902+
898903
def test_none(self) -> None:
899904
self.assert_meet(NoneType(), NoneType(), NoneType())
900905

0 commit comments

Comments
 (0)