Allow TypeVarTuple as type argument for subclasses of generic TypedDict
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die beiden Reproduktionen typeddict_typevartuple_310.py und typeddict_typevartuple_311.py mit dem gemeldeten mypy-Verhalten auszuführen. Verfolge die durch diese Beispiele erreichte Validierung generischer Typargumente für TypedDict und füge anschließend eine gezielte Abdeckung sowohl für Unpack- als auch für Stern-Entpackungsformen hinzu. Die Aufgabe ist erledigt, wenn mypy beide abgeleiteten TypedDict-Definitionen ohne die gemeldeten Fehler akzeptiert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers, devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100