Skip to content

Commit d5318cd

Browse files
simplify treatment of typevar argument
1 parent fecb496 commit d5318cd

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

mypy/subtypes.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,8 @@ def restrict_subtype_away(t: Type, s: Type, *, consider_runtime_isinstance: bool
20952095
"""
20962096
p_t = get_proper_type(t)
20972097
s_t = get_proper_type(s)
2098+
if isinstance(s_t, TypeVarType):
2099+
s = s_t.upper_bound
20982100

20992101
if isinstance(p_t, UnionType):
21002102
new_items = try_restrict_literal_union(p_t, s)
@@ -2109,15 +2111,7 @@ def restrict_subtype_away(t: Type, s: Type, *, consider_runtime_isinstance: bool
21092111
[item for item in new_items if not isinstance(get_proper_type(item), UninhabitedType)]
21102112
)
21112113
elif isinstance(p_t, TypeVarType):
2112-
if isinstance(s_t, TypeVarType):
2113-
upper_bound = restrict_subtype_away(p_t.upper_bound, s_t.upper_bound)
2114-
upper_bound = get_proper_type(upper_bound)
2115-
return (
2116-
upper_bound
2117-
if isinstance(upper_bound, UninhabitedType)
2118-
else p_t.copy_modified(upper_bound=upper_bound)
2119-
)
2120-
return p_t.copy_modified(upper_bound=restrict_subtype_away(p_t.upper_bound, s_t))
2114+
return p_t.copy_modified(upper_bound=restrict_subtype_away(p_t.upper_bound, s))
21212115

21222116
if consider_runtime_isinstance:
21232117
if covers_at_runtime(t, s):

0 commit comments

Comments
 (0)