Skip to content

Commit 8573706

Browse files
committed
microoptimise
1 parent e880af6 commit 8573706

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

mypy/subtypes.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,13 +2087,17 @@ def restrict_subtype_away(t: Type, s: Type, *, consider_runtime_isinstance: bool
20872087
)
20882088
elif isinstance(p_t, TypeVarType):
20892089
return p_t.copy_modified(upper_bound=restrict_subtype_away(p_t.upper_bound, s))
2090-
elif consider_runtime_isinstance and covers_at_runtime(t, s):
2091-
return UninhabitedType()
2092-
elif is_proper_subtype(t, s, ignore_promotions=True):
2093-
return UninhabitedType()
2094-
elif is_proper_subtype(t, s, ignore_promotions=True, erase_instances=True):
2095-
return UninhabitedType()
2090+
2091+
if consider_runtime_isinstance:
2092+
if covers_at_runtime(t, s):
2093+
return UninhabitedType()
2094+
else:
2095+
return t
20962096
else:
2097+
if is_proper_subtype(t, s, ignore_promotions=True):
2098+
return UninhabitedType()
2099+
if is_proper_subtype(t, s, ignore_promotions=True, erase_instances=True):
2100+
return UninhabitedType()
20972101
return t
20982102

20992103

0 commit comments

Comments
 (0)