*Memo:
- mypy test.py
- mypy 1.19.1
- Python 3.14
- Windows 11
The docstring of ParamSpec shows two examples using the default value with a tuple as shown below:
from typing import ParamSpec
print(help(ParamSpec))
type IntFuncDefault[**P = (int, str)] = Callable[P, int]
P = ParamSpec('P')
DefaultP = ParamSpec('DefaultP', default=(int, str))
But mypy gives the error because a tuple is set instead of a list as shown below:
from typing import ParamSpec
# ↓ tuple ↓
type IntFuncDefault[**P = (int, str)] = Callable[P, int] # Error
P = ParamSpec('P') # ↓ tuple ↓
DefaultP = ParamSpec('DefaultP', default=(int, str)) # Error
error: The default argument to ParamSpec must be a list expression, ellipsis, or a ParamSpec
Actually, setting a list gets no error as shown below:
from typing import ParamSpec
# ↓ list ↓
type IntFuncDefault[**P = [int, str]] = Callable[P, int] # No error
P = ParamSpec('P') # ↓ list ↓
DefaultP = ParamSpec('DefaultP', default=[int, str]) # No error
So using ParamSpec, mypy shouldn't give error with a tuple but should give error with a list as a default value, following the docstring.