2Tests the handling of a ParamSpec specialization.
5from typing import Any, Callable, Concatenate, Generic, ParamSpec, TypeVar, cast
13class ClassA(Generic[T, P1]):
14 f: Callable[P1, int] = cast(Any, "")
18class ClassB(ClassA[T, P1], Generic[T, P1, P2]):
19 f1: Callable[P1, int] = cast(Any, "")
20 f2: Callable[P2, int] = cast(Any, "")
24def func20(x: ClassA[int, P2]) -> str: # OK
28def func21(x: ClassA[int, Concatenate[int, P2]]) -> str: # OK
32def func22(x: ClassB[int, [int, bool], ...]) -> str: # OK
36def func23(x: ClassA[int, ...]) -> str: # OK
40def func24(x: ClassB[int, [], []]) -> str: # OK
44def func25(x: ClassA[int, int]) -> str: # E
[invalid-type-arguments] Type argument for `ParamSpec` must be either a list of types, `ParamSpec`, `Concatenate`, or `...`
48class ClassC(Generic[P1]):
49 f: Callable[P1, int] = cast(Any, "")
52def func30(x: ClassC[[int, str, bool]]) -> None: # OK
[invalid-argument-type] Argument is incorrect: Expected `int`, found `Literal[""]`
[invalid-argument-type] Argument is incorrect: Expected `bool`, found `Literal[""]`
58def func31(x: ClassC[int, str, bool]) -> None: # OK
[invalid-argument-type] Argument is incorrect: Expected `int`, found `Literal[""]`
[invalid-argument-type] Argument is incorrect: Expected `bool`, found `Literal[""]`