Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6071,6 +6071,8 @@ def analyze_type_application_args(self, expr: IndexExpr) -> list[Type] | None:
return None
types.append(analyzed)

if allow_unpack:
types = self.type_analyzer().check_unpacks_in_list(types)
if has_param_spec and num_args == 1 and types:
first_arg = get_proper_type(types[0])
single_any = len(types) == 1 and isinstance(first_arg, AnyType)
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,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)
self.fail("More than one 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
13 changes: 13 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -2029,3 +2029,16 @@ def foo() -> None:
class Z: ... # E: Name "Z" already defined on line 2
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]

[case testPEP695MultipleUnpacksInBareApplicationNoCrash]
# https://github.com/python/mypy/issues/18856
class A[*Ts]: ...

A[*tuple[int, ...], *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

tuple[*tuple[int, ...], *tuple[int, ...]] # E: More than one Unpack in a type is not allowed
b: tuple[*tuple[int, ...], *tuple[int, ...]] # E: More than one Unpack in a type is not allowed
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]