Skip to content

Commit 01c40e3

Browse files
committed
Fix constraint solver and subclass check
1 parent 7175f51 commit 01c40e3

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
@@ -226,6 +226,8 @@ def _infer_constraints(template: Type, actual: Type, direction: int) -> list[Con
226226
template = mypy.typeops.make_simplified_union(template.items, keep_erased=True)
227227
if isinstance(actual, UnionType):
228228
actual = mypy.typeops.make_simplified_union(actual.items, keep_erased=True)
229+
if isinstance(actual, TypeVarType) and actual.has_default():
230+
actual = actual.default
229231

230232
# Ignore Any types from the type suggestion engine to avoid them
231233
# 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
@@ -290,6 +290,9 @@ def _is_subtype(
290290
# ErasedType as we do for non-proper subtyping.
291291
return True
292292

293+
if not proper_subtype and isinstance(right, TypeVarType) and right.has_default():
294+
return left.accept(SubtypeVisitor(right.default, subtype_context, proper_subtype))
295+
293296
if isinstance(right, UnionType) and not isinstance(left, UnionType):
294297
# Normally, when 'left' is not itself a union, the only way
295298
# 'left' can be a subtype of the union 'right' is if it is a

0 commit comments

Comments
 (0)