2Tests basic usage of ParamSpec.
5# Specification: https://typing.readthedocs.io/en/latest/spec/generics.html#paramspec-variables
7from typing import Any, Callable, Concatenate, ParamSpec, TypeAlias
10WrongName = ParamSpec("NotIt") # E: name inconsistency
[invalid-paramspec] The name of a `ParamSpec` (`NotIt`) must match the name of the variable it is assigned to (`WrongName`)
13# > Valid use locations
Expected a ty diagnostic for this line
17TA2: TypeAlias = Callable[P, None] # OK
18TA3: TypeAlias = Callable[Concatenate[int, P], None] # OK
19TA4: TypeAlias = Callable[..., None] # OK
20TA5: TypeAlias = Callable[..., None] # OK
23def func1(x: P) -> P: # E
[empty-body] Function always implicitly returns `None`, which is not assignable to return type `P@func1`
27def func2(x: Concatenate[int, P]) -> int: # E
Expected a ty diagnostic for this line
28 raise NotImplementedError
31def func3(x: list[P]) -> None: # E
Expected a ty diagnostic for this line
35def func4(x: Callable[[int, str], P]) -> None: # E
Expected a ty diagnostic for this line
39def func5(*args: P, **kwargs: P) -> None: # E
Expected a ty diagnostic for this line