Skip to content

Commit a63b5c9

Browse files
committed
Check and fix unpacks early - normally does that, but semanal uses its own anal_type wrapper in a loop
1 parent a069741 commit a63b5c9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mypy/semanal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6071,6 +6071,9 @@ def analyze_type_application_args(self, expr: IndexExpr) -> list[Type] | None:
60716071
return None
60726072
types.append(analyzed)
60736073

6074+
analyzer = self.type_analyzer()
6075+
types = analyzer.check_unpacks_in_list(types)
6076+
60746077
if has_param_spec and num_args == 1 and types:
60756078
first_arg = get_proper_type(types[0])
60766079
single_any = len(types) == 1 and isinstance(first_arg, AnyType)

test-data/unit/check-python312.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,3 +2029,13 @@ def foo() -> None:
20292029
class Z: ... # E: Name "Z" already defined on line 2
20302030
[builtins fixtures/tuple.pyi]
20312031
[typing fixtures/typing-full.pyi]
2032+
2033+
[case testPEP695MultipleUnpacksInBareApplicationNoCrash]
2034+
# https://github.com/python/mypy/issues/18856
2035+
class A[*Ts]: ...
2036+
2037+
A[*tuple[int, ...], *tuple[int, ...]] # E: More than one Unpack in a type is not allowed
2038+
2039+
b: tuple[*tuple[int, ...], *tuple[int, ...]] # E: More than one Unpack in a type is not allowed
2040+
[builtins fixtures/tuple.pyi]
2041+
[typing fixtures/typing-full.pyi]

0 commit comments

Comments
 (0)