Allow TypeVarTuple as type argument for subclasses of generic TypedDict
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo le due riproduzioni, typeddict_typevartuple_310.py e typeddict_typevartuple_311.py, con il comportamento di mypy segnalato. Traccia la validazione degli argomenti di tipo generici di TypedDict raggiunta da questi esempi, quindi aggiungi una copertura mirata sia per le forme con Unpack sia per le forme di spacchettamento con asterisco. Il lavoro è completato quando mypy accetta entrambe le definizioni TypedDict derivate senza gli errori segnalati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers, devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100