From dff33a1d296538cd7cfd046317aab31740b59ab0 Mon Sep 17 00:00:00 2001 From: cyphercodes Date: Tue, 5 May 2026 18:23:45 +0300 Subject: [PATCH] Fix nested Concatenate with ellipsis crash Fixes #21404. --- mypy/typeanal.py | 3 +++ test-data/unit/check-parameter-specification.test | 1 + 2 files changed, 4 insertions(+) diff --git a/mypy/typeanal.py b/mypy/typeanal.py index db56256192625..9ece662e97b2a 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -580,6 +580,9 @@ def apply_concatenate_operator(self, t: UnboundType) -> Type: self.api.fail("Nested Concatenates are invalid", t, code=codes.VALID_TYPE) args = self.anal_array(t.args[:-1]) + if any(isinstance(arg, (Parameters, ParamSpecType)) for arg in args): + self.api.fail("Nested Concatenates are invalid", t, code=codes.VALID_TYPE) + return AnyType(TypeOfAny.from_error) pre = ps.prefix if isinstance(ps, ParamSpecType) else ps # mypy can't infer this :( diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index 970ba45d0e8e2..294790ef330a2 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -1147,6 +1147,7 @@ from typing import Callable P = ParamSpec("P") def x(f: Callable[Concatenate[int, Concatenate[int, P]], None]) -> None: ... # E: Nested Concatenates are invalid +def y(f: Callable[Concatenate[Concatenate[...], ...], None]) -> None: ... # E: Nested Concatenates are invalid [builtins fixtures/paramspec.pyi] [case testPropagatedAnyConstraintsAreOK]