mypy
mypy copied to clipboard
constrained TypeVar and star operator incompatible type
Bug Report We can't use TypeVar with star operator, maybe I wrongly used TypeVar. Thanks
To Reproduce
T = TypeVar("T", str, int)
def test(a: Sequence[T]) -> list[T]:
return [*a]
Expected Behavior No error
Actual Behavior
cactus.py: note: In function "test":
cactus.py:57:14: error: List item 0 has incompatible type "Sequence[T]"; expected "str" [list-item]
return [*a]
^
cactus.py:57:14: error: List item 0 has incompatible type "Sequence[T]"; expected "int" [list-item]
return [*a]
^
cactus.py:57:14: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-list-item for more info
Your Environment
- Mypy version used: 1.11.1
- Python version used: 3.12.1