|
7 | 7 | UninhabitedType, TypeType, TypeOfAny, Overloaded, FunctionLike, LiteralType,
|
8 | 8 | ProperType, get_proper_type, get_proper_types, TypeAliasType, TypeGuardType
|
9 | 9 | )
|
| 10 | +from mypy.sametypes import is_same_type |
10 | 11 | from mypy.subtypes import is_equivalent, is_subtype, is_callable_compatible, is_proper_subtype
|
11 | 12 | from mypy.erasetype import erase_type
|
12 | 13 | from mypy.maptype import map_instance_to_supertype
|
@@ -45,6 +46,8 @@ def meet_types(s: Type, t: Type) -> ProperType:
|
45 | 46 | return t
|
46 | 47 | if isinstance(s, UnionType) and not isinstance(t, UnionType):
|
47 | 48 | s, t = t, s
|
| 49 | + if isinstance(s, TypeVarType) and not isinstance(t, TypeVarType): |
| 50 | + s, t = t, s |
48 | 51 | return t.accept(TypeMeetVisitor(s))
|
49 | 52 |
|
50 | 53 |
|
@@ -483,7 +486,8 @@ def visit_erased_type(self, t: ErasedType) -> ProperType:
|
483 | 486 | def visit_type_var(self, t: TypeVarType) -> ProperType:
|
484 | 487 | if isinstance(self.s, TypeVarType) and self.s.id == t.id:
|
485 | 488 | 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))): |
487 | 491 | return t
|
488 | 492 | else:
|
489 | 493 | return self.default(self.s)
|
|
0 commit comments