diff --git a/mypy/semanal.py b/mypy/semanal.py index 782985e3fbab..aff2b02869f6 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -5904,9 +5904,8 @@ def analyze_type_application_args(self, expr: IndexExpr) -> list[Type] | None: if has_param_spec and num_args == 1 and types: first_arg = get_proper_type(types[0]) - if not ( - len(types) == 1 and isinstance(first_arg, (Parameters, ParamSpecType, AnyType)) - ): + single_any = len(types) == 1 and isinstance(first_arg, AnyType) + if not (single_any or any(isinstance(t, (Parameters, ParamSpecType)) for t in types)): types = [Parameters(types, [ARG_POS] * len(types), [None] * len(types))] return types diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index c2afb61586a8..654f36775172 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -1836,6 +1836,15 @@ c: C[int, [int, str], str] # E: Nested parameter specifications are not allowed reveal_type(c) # N: Revealed type is "__main__.C[Any]" [builtins fixtures/paramspec.pyi] +[case testParamSpecInheritNoCrashOnNested] +from typing import Generic +from typing_extensions import ParamSpec + +P = ParamSpec("P") +class C(Generic[P]): ... +class D(C[int, [int, str], str]): ... # E: Nested parameter specifications are not allowed +[builtins fixtures/paramspec.pyi] + [case testParamSpecConcatenateSelfType] from typing import Callable from typing_extensions import ParamSpec, Concatenate