Skip to content

Commit fafe542

Browse files
committed
Use is_subtype instead of combination of meet_types and is_same_type
1 parent e04dd2e commit fafe542

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

mypy/meet.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
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
1110
from mypy.subtypes import is_equivalent, is_subtype, is_callable_compatible, is_proper_subtype
1211
from mypy.erasetype import erase_type
1312
from mypy.maptype import map_instance_to_supertype
@@ -71,17 +70,15 @@ def narrow_declared_type(declared: Type, narrowed: Type) -> Type:
7170
for x in narrowed.relevant_items()])
7271
elif isinstance(narrowed, AnyType):
7372
return narrowed
73+
elif isinstance(narrowed, TypeVarType) and is_subtype(narrowed.upper_bound, declared):
74+
return narrowed
7475
elif isinstance(declared, TypeType) and isinstance(narrowed, TypeType):
7576
return TypeType.make_normalized(narrow_declared_type(declared.item, narrowed.item))
7677
elif (isinstance(declared, TypeType)
7778
and isinstance(narrowed, Instance)
7879
and narrowed.type.is_metaclass()):
7980
# We'd need intersection types, so give up.
8081
return declared
81-
elif isinstance(narrowed, TypeVarType):
82-
if is_same_type(narrowed.upper_bound, meet_types(narrowed.upper_bound, declared)):
83-
return narrowed
84-
return meet_types(declared, narrowed)
8582
elif isinstance(declared, (Instance, TupleType, TypeType, LiteralType)):
8683
return meet_types(declared, narrowed)
8784
elif isinstance(declared, TypedDictType) and isinstance(narrowed, Instance):

0 commit comments

Comments
 (0)