Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix crash with nested tuple
  • Loading branch information
randolf-scholz committed Aug 21, 2025
commit 1a2a5b876d14f8a3b0aaeb58ce9a3087f85abb8c
4 changes: 2 additions & 2 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ def check_unpacks_in_list(self, items: list[Type]) -> list[Type]:
new_items: list[Type] = []
num_unpacks = 0
final_unpack = None
for item in items:
for item in flatten_nested_tuples(items):
# TODO: handle forward references here, they appear as Unpack[Any].
if isinstance(item, UnpackType) and not isinstance(
get_proper_type(item.type), TupleType
Expand All @@ -1978,7 +1978,7 @@ def check_unpacks_in_list(self, items: list[Type]) -> list[Type]:

if num_unpacks > 1:
assert final_unpack is not None
self.fail("More than one Unpack in a type is not allowed", final_unpack.type)
self.fail("More than one variable Unpack in a type is not allowed", final_unpack.type)
return new_items

def tuple_type(self, items: list[Type], line: int, column: int) -> TupleType:
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,7 @@ class Z: ... # E: Name "Z" already defined on line 2
class A[*Ts]: ...

A[*tuple[int, ...], *tuple[int, ...]] # E: More than one Unpack in a type is not allowed
A[*tuple[*tuple[int, ...]], *tuple[*tuple[int, ...]]] # E: More than one Unpack in a type is not allowed
a: A[*tuple[int, ...], *tuple[int, ...]] # E: More than one Unpack in a type is not allowed
def foo(a: A[*tuple[int, ...], *tuple[int, ...]]): ... # E: More than one Unpack in a type is not allowed

Expand Down
Loading