Skip to content

Commit 6107b0c

Browse files
committed
Better solution for is_subtype check
1 parent 6772805 commit 6107b0c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

mypy/subtypes.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ def _is_subtype(
303303
# ErasedType as we do for non-proper subtyping.
304304
return True
305305

306-
if not proper_subtype and isinstance(right, TypeVarType) and right.has_default():
307-
return left.accept(SubtypeVisitor(right.default, subtype_context, proper_subtype))
308-
309306
if isinstance(right, UnionType) and not isinstance(left, UnionType):
310307
# Normally, when 'left' is not itself a union, the only way
311308
# 'left' can be a subtype of the union 'right' is if it is a
@@ -629,8 +626,9 @@ def visit_instance(self, left: Instance) -> bool:
629626
if call:
630627
return self._is_subtype(call, right)
631628
return False
632-
else:
633-
return False
629+
if isinstance(right, TypeVarType) and right.has_default():
630+
return self._is_subtype(left, right.default)
631+
return False
634632

635633
def visit_type_var(self, left: TypeVarType) -> bool:
636634
right = self.right

0 commit comments

Comments
 (0)