From 8b6bafce1b99a30309b85d66fcd9b138722f2f20 Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Fri, 13 Sep 2024 09:43:00 -0400 Subject: [PATCH 1/2] Fix crash when passing multiple type args to base expecting 1 ParamSpec --- mypy/semanal.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 From 73f4635a31f31a10721e22baab924a3042bce3de Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Fri, 13 Sep 2024 09:58:49 -0400 Subject: [PATCH 2/2] Add test case for crash reproducer --- test-data/unit/check-parameter-specification.test | 9 +++++++++ 1 file changed, 9 insertions(+) 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