@@ -223,7 +223,7 @@ def visit_instance(self, t: Instance) -> Type: |
223 | 223 | # See: https://github.com/python/mypy/issues/16649 |
224 | 224 | return t.copy_modified(args=args) |
225 | 225 |
|
226 | | - if t.type.fullname == "builtins.tuple": |
| 226 | + if t.type.fullname == "builtins.tuple" and len(args) > 0: |
227 | 227 | # Normalize Tuple[*Tuple[X, ...], ...] -> Tuple[X, ...] |
228 | 228 | arg = args[0] |
229 | 229 | if isinstance(arg, UnpackType): |
@@ -519,7 +519,15 @@ def expand_type_list_with_unpack(self, typs: list[Type]) -> list[Type]: |
519 | 519 | if isinstance(item, UnpackType) and isinstance(item.type, TypeVarTupleType): |
520 | 520 | items.extend(self.expand_unpack(item)) |
521 | 521 | else: |
522 | | - items.append(item.accept(self)) |
| 522 | + expanded = item.accept(self) |
| 523 | + if isinstance(expanded, UnpackType) and isinstance( |
| 524 | + expanded.type, TupleType |
| 525 | + ): |
| 526 | + # Inline Unpack[tuple[X, Y]] -> X, Y |
| 527 | + # This handles e.g. Unpack[tuple[()]] -> nothing |
| 528 | + items.extend(expanded.type.items) |
| 529 | + continue |
| 530 | + items.append(expanded) |
523 | 531 | return items |
524 | 532 |
|
525 | 533 | def expand_type_tuple_with_unpack(self, typs: tuple[Type, ...]) -> list[Type]: |
@@ -530,7 +538,15 @@ def expand_type_tuple_with_unpack(self, typs: tuple[Type, ...]) -> list[Type]: |
530 | 538 | if isinstance(item, UnpackType) and isinstance(item.type, TypeVarTupleType): |
531 | 539 | items.extend(self.expand_unpack(item)) |
532 | 540 | else: |
533 | | - items.append(item.accept(self)) |
| 541 | + expanded = item.accept(self) |
| 542 | + if isinstance(expanded, UnpackType) and isinstance( |
| 543 | + expanded.type, TupleType |
| 544 | + ): |
| 545 | + # Inline Unpack[tuple[X, Y]] -> X, Y |
| 546 | + # This handles e.g. Unpack[tuple[()]] -> nothing |
| 547 | + items.extend(expanded.type.items) |
| 548 | + continue |
| 549 | + items.append(expanded) |
534 | 550 | return items |
535 | 551 |
|
536 | 552 | def visit_tuple_type(self, t: TupleType) -> Type: |
|