Skip to content

Commit 1a2a5b8

Browse files
fix crash with nested tuple
1 parent b99948b commit 1a2a5b8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

mypy/typeanal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,7 @@ def check_unpacks_in_list(self, items: list[Type]) -> list[Type]:
19641964
new_items: list[Type] = []
19651965
num_unpacks = 0
19661966
final_unpack = None
1967-
for item in items:
1967+
for item in flatten_nested_tuples(items):
19681968
# TODO: handle forward references here, they appear as Unpack[Any].
19691969
if isinstance(item, UnpackType) and not isinstance(
19701970
get_proper_type(item.type), TupleType
@@ -1978,7 +1978,7 @@ def check_unpacks_in_list(self, items: list[Type]) -> list[Type]:
19781978

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

19841984
def tuple_type(self, items: list[Type], line: int, column: int) -> TupleType:

test-data/unit/check-python312.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,7 @@ class Z: ... # E: Name "Z" already defined on line 2
20392039
class A[*Ts]: ...
20402040

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

0 commit comments

Comments
 (0)