Open
Description
Bug Report
I have a TypedDict
class which has TypeVarTuple
type argument(s), and that works as I would expect. However, when I try to make a class derived from that base class, I get unexpected errors from mypy. Different errors, actually, depending on whether I use Unpack
or the new "star" unpacking syntax.
This all ought to work, though, right?
To Reproduce
# typeddict_typevartuple_310.py
from collections.abc import Callable
from typing import Generic, Tuple, TypedDict, TypeVar
from typing_extensions import TypeVarTuple, Unpack
ATs = TypeVarTuple('ATs')
RT = TypeVar('RT')
class BaseDict(TypedDict, Generic[Unpack[ATs], RT]):
callback: Callable[[Unpack[ATs]], RT]
arguments: Tuple[Unpack[ATs]]
class DerivedDict(BaseDict[Unpack[ATs], RT]): # E: Unpack is only valid in a variadic position
returned: RT
# typeddict_typevartuple_311.py
from collections.abc import Callable
from typing import Generic, TypedDict, TypeVar, TypeVarTuple
ATs = TypeVarTuple('ATs')
RT = TypeVar('RT')
class BaseDict(TypedDict, Generic[*ATs, RT]):
callback: Callable[[*ATs], RT]
arguments: tuple[*ATs]
class DerivedDict(BaseDict[*ATs, RT]): # E: Invalid TypedDict type argument
returned: RT
Expected Behavior
I would have expected mypy to accept both these versions as correct...
Actual Behavior
... But it fails both of them, with distinct messages (see inline comments).
Your Environment
- Mypy version used: mypy 1.10.0+dev.3c87af272cbf7c49699b7508c7f51365da139c05 (compiled: no)
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini
(and other config files): n/a - Python version used: 3.10 and 3.11