mypy flags "overlap between argument names and ** TypedDict items" with total=False
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
mypy complains about explicit kwargs of a function appearing in the Unpacked TypedDict used for the ** parameter, even if the TypedDict is total=False.
To Reproduce
from typing import TypedDict, Unpack
class Opts(TypedDict, total=False):
verbose: bool
other: str
def do_a(*, verbose: bool = False, **_kwargs: Unpack[Opts]) -> None:
pass
def do_b(**kwargs: Unpack[Opts]) -> None:
pass
def do_thing(cmd: str, **kwargs: Unpack[Opts]) -> None:
match cmd:
case 'a':
do_a(**kwargs)
case 'b':
do_b(**kwargs)
https://mypy-play.net/?mypy=latest&python=3.12&gist=a7836435f32a3fab9c3e671b73897370
Expected Behavior
I expect that this should be completely fine. Yes, verbose might end up being "stolen" away from the **kwargs in do_a() but that's quite fine, since total=False there anyway. There is no promise/expectation that verbose will be included.
Actual Behavior
main.py:9: error: Overlap between argument names and ** TypedDict items: "verbose" [misc]
Your Environment
I'm running on Fedora 42 (mypy 1.15.0 (compiled: no)), but the playground gets exactly the same error.
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 con il riproduttore minimo in main.py oppure eseguilo nel mypy playground collegato e conferma la diagnostica di sovrapposizione alla riga 9. Traccia il punto di ingresso del type checking di mypy che segnala «Overlap between argument names and ** TypedDict items» per un Unpack’ed total=False TypedDict. Il lavoro è completato quando il riproduttore non segnala più questo errore, mentre il resto del comportamento di tipizzazione continua a essere verificato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 52/100