@@ -81,9 +81,6 @@ def valid[**P](
8181def invalid[** P](
8282 # error: [invalid-type-form] "Bare ParamSpec `P` is not valid in this context"
8383 a1: P,
84- # TODO : this should cause us to emit an error because a `ParamSpec` type argument
85- # cannot be used to specialize a non-`ParamSpec` type parameter
86- a2: list[P],
8784 # error: [invalid-type-form] "Bare ParamSpec `P` is not valid in this context"
8885 a3: Callable[[P], int ],
8986 # error: [invalid-type-form] "Bare ParamSpec `P` is not valid in this context"
@@ -379,6 +376,44 @@ both mypy and Pyright allow this and there are usages of this in the wild e.g.,
379376reveal_type(TypeVarAndParamSpec[int , Any]().attr) # revealed: (...) -> int
380377```
381378
379+ ## ` ParamSpec ` cannot specialize a ` TypeVar ` , and vice versa
380+
381+ <!-- snapshot-diagnostics -->
382+
383+ A ` ParamSpec ` is not a valid type argument for a regular ` TypeVar ` , and vice versa.
384+
385+ ``` py
386+ from typing import Callable
387+
388+ class OnlyTypeVar[T]:
389+ attr: T
390+
391+ class TypeVarAndParamSpec[T, ** P]:
392+ attr: Callable[P, T]
393+
394+ def f[** P, T]():
395+ # error: [invalid-type-arguments] "ParamSpec `P` cannot be used to specialize type variable `T`"
396+ a: OnlyTypeVar[P]
397+
398+ # error: [invalid-type-arguments] "ParamSpec `P` cannot be used to specialize type variable `T`"
399+ b: TypeVarAndParamSpec[P, [int ]]
400+
401+ class OnlyParamSpec[** P]:
402+ attr: Callable[P, None ]
403+
404+ # This is fine due to the special case whereby `OnlyParamSpec[T]` is interpreted the same as
405+ # `OnlyParamSpec[[T]]`, due to the fact that `OnlyParamSpec` is only generic over a single
406+ # `ParamSpec` and no other type variables.
407+ def func2[T](c: OnlyParamSpec[T], other: T):
408+ reveal_type(c.attr) # revealed: (T@func2, /) -> None
409+
410+ class ParamSpecAndTypeVar[** P, T]:
411+ attr: Callable[P, T]
412+
413+ # error: [invalid-type-arguments] "Type argument for `ParamSpec` must be either a list of types, `ParamSpec`, `Concatenate`, or `...`"
414+ def func3[T](c: ParamSpecAndTypeVar[T, int ], other: T): ...
415+ ```
416+
382417## Specialization when defaults are involved
383418
384419``` py
0 commit comments