Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mypy/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def visit_erased_type(self, t: ErasedType) -> ProperType:
return self.s

def visit_type_var(self, t: TypeVarType) -> ProperType:
if is_subtype(self.s, t):
return t
if isinstance(self.s, TypeVarType):
if self.s.id == t.id:
if self.s.upper_bound == t.upper_bound:
Expand Down
13 changes: 13 additions & 0 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ def _is_subtype(
# ErasedType as we do for non-proper subtyping.
return True

if isinstance(right, TypeVarType) and right.values:
if isinstance(left, TypeVarType) and left.id == right.id:
return True
if proper_subtype:
return all(
is_proper_subtype(orig_left, v, subtype_context=subtype_context)
for v in right.values
)
else:
return all(
is_subtype(orig_left, v, subtype_context=subtype_context) for v in right.values
)

if isinstance(right, UnionType) and not isinstance(left, UnionType):
# Normally, when 'left' is not itself a union, the only way
# 'left' can be a subtype of the union 'right' is if it is a
Expand Down
Loading