@@ -224,6 +224,10 @@ def visit_instance(self, t: Instance) -> Type: |
224 | 224 | return t.copy_modified(args=args) |
225 | 225 |
|
226 | 226 | if t.type.fullname == "builtins.tuple": |
| 227 | + if not args: |
| 228 | + # After expansion, args is empty (e.g. Unpack[tuple[()]] expanded |
| 229 | + # to nothing). Return the empty fixed-length tuple tuple[()]. |
| 230 | + return TupleType([], fallback=t.copy_modified(args=[])) |
227 | 231 | # Normalize Tuple[*Tuple[X, ...], ...] -> Tuple[X, ...] |
228 | 232 | arg = args[0] |
229 | 233 | if isinstance(arg, UnpackType): |
@@ -519,7 +523,15 @@ def expand_type_list_with_unpack(self, typs: list[Type]) -> list[Type]: |
519 | 523 | if isinstance(item, UnpackType) and isinstance(item.type, TypeVarTupleType): |
520 | 524 | items.extend(self.expand_unpack(item)) |
521 | 525 | else: |
522 | | - items.append(item.accept(self)) |
| 526 | + expanded = item.accept(self) |
| 527 | + if isinstance(expanded, UnpackType) and isinstance( |
| 528 | + expanded.type, TupleType |
| 529 | + ): |
| 530 | + # Inline Unpack[tuple[X, Y]] -> X, Y |
| 531 | + # This also handles Unpack[tuple[()]] -> nothing |
| 532 | + items.extend(expanded.type.items) |
| 533 | + continue |
| 534 | + items.append(expanded) |
523 | 535 | return items |
524 | 536 |
|
525 | 537 | def expand_type_tuple_with_unpack(self, typs: tuple[Type, ...]) -> list[Type]: |
@@ -530,7 +542,15 @@ def expand_type_tuple_with_unpack(self, typs: tuple[Type, ...]) -> list[Type]: |
530 | 542 | if isinstance(item, UnpackType) and isinstance(item.type, TypeVarTupleType): |
531 | 543 | items.extend(self.expand_unpack(item)) |
532 | 544 | else: |
533 | | - items.append(item.accept(self)) |
| 545 | + expanded = item.accept(self) |
| 546 | + if isinstance(expanded, UnpackType) and isinstance( |
| 547 | + expanded.type, TupleType |
| 548 | + ): |
| 549 | + # Inline Unpack[tuple[X, Y]] -> X, Y |
| 550 | + # This also handles Unpack[tuple[()]] -> nothing |
| 551 | + items.extend(expanded.type.items) |
| 552 | + continue |
| 553 | + items.append(expanded) |
534 | 554 | return items |
535 | 555 |
|
536 | 556 | def visit_tuple_type(self, t: TupleType) -> Type: |
|