Skip to content

Commit 2e90e9f

Browse files
committed
Fix join of Tuple and NamedTuple
1 parent a72c71b commit 2e90e9f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mypy/subtypes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,15 @@ def visit_instance(self, left: Instance) -> bool:
143143
rname = right.type.fullname()
144144
if not left.type.has_base(rname) and rname != 'builtins.object':
145145
return False
146-
147146
# Map left type to corresponding right instances.
148147
t = map_instance_to_supertype(left, right.type)
149-
148+
# Check that one of the types does not have type args or
149+
# the number of type args is the same and
150+
# each left type arg is acceptable in place of the matching right one
151+
if not t.args or not right.args:
152+
return True
153+
if len(t.args) != len(right.args):
154+
return False
150155
return all(self.check_type_parameter(lefta, righta, tvar.variance)
151156
for lefta, righta, tvar in
152157
zip(t.args, right.args, right.type.defn.type_vars))

mypy/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ def visit_tuple_type(self, t: TupleType) -> str:
14281428
s = self.list_str(t.items)
14291429
if t.fallback and t.fallback.type:
14301430
fallback_name = t.fallback.type.fullname()
1431-
if fallback_name != 'builtins.tuple':
1431+
if fallback_name not in ('builtins.tuple', 'builtins.object'):
14321432
return 'Tuple[{}, fallback={}]'.format(s, t.fallback.accept(self))
14331433
return 'Tuple[{}]'.format(s)
14341434

0 commit comments

Comments
 (0)