Skip to content

Commit 47ebf8d

Browse files
committed
Fix noncommutative joins with bounded TypeVars
Fixes #20344
1 parent ece4d41 commit 47ebf8d

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

mypy/join.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,15 @@ def visit_erased_type(self, t: ErasedType) -> ProperType:
297297
return self.s
298298

299299
def visit_type_var(self, t: TypeVarType) -> ProperType:
300-
if isinstance(self.s, TypeVarType) and self.s.id == t.id:
301-
if self.s.upper_bound == t.upper_bound:
302-
return self.s
303-
return self.s.copy_modified(upper_bound=join_types(self.s.upper_bound, t.upper_bound))
300+
if isinstance(self.s, TypeVarType):
301+
if self.s.id == t.id:
302+
if self.s.upper_bound == t.upper_bound:
303+
return self.s
304+
return self.s.copy_modified(
305+
upper_bound=join_types(self.s.upper_bound, t.upper_bound)
306+
)
307+
# Fix non-commutative joins
308+
return get_proper_type(join_types(self.s.upper_bound, t.upper_bound))
304309
else:
305310
return self.default(self.s)
306311

0 commit comments

Comments
 (0)