Skip to content

Commit 6772805

Browse files
committed
Fix constraint solver and subclass check
1 parent 4a454ea commit 6772805

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

mypy/constraints.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ def _infer_constraints(
328328
template = mypy.typeops.make_simplified_union(template.items, keep_erased=True)
329329
if isinstance(actual, UnionType):
330330
actual = mypy.typeops.make_simplified_union(actual.items, keep_erased=True)
331+
if isinstance(actual, TypeVarType) and actual.has_default():
332+
actual = get_proper_type(actual.default)
331333

332334
# Ignore Any types from the type suggestion engine to avoid them
333335
# causing us to infer Any in situations where a better job could

mypy/subtypes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ 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+
306309
if isinstance(right, UnionType) and not isinstance(left, UnionType):
307310
# Normally, when 'left' is not itself a union, the only way
308311
# 'left' can be a subtype of the union 'right' is if it is a

0 commit comments

Comments
 (0)