Incorrect error when argument missing from function call unpacking 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
When supplying arguments by unpacking a TypedDict, and the TypedDict does not supply all the parameters, mypy seems to treat it as only supplying the first parameter, even if that is the one that is missing.
To Reproduce
from typing import TypedDict
def my_function(foo: int, bar: int) -> None:
pass
class MyTypedDict(TypedDict):
# foo: int
bar: int
a: MyTypedDict = {'bar': 1}
my_function(**a) # mypy - error: Missing positional argument "bar" in call to "my_function"
my_function(bar=1) # mypy - error: Missing positional argument "foo" in call to "my_function"
https://mypy-play.net/?mypy=0.931&python=3.11&flags=strict&gist=c72be0814d2e7684453f2a8825f2e986
Expected Behavior
The line my_function(**a) should result in mypy error error: Missing positional argument "foo" in call to "my_function", as it only supplies bar.
Actual Behavior
The line my_function(**a) resulted in mypy error error: Missing positional argument "bar" in call to "my_function".
When executed, python gave this error:
TypeError: my_function() missing 1 required positional argument: 'foo'
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 il riproduttore fornito di mypy-play per TypedDict e function-unpacking e confronta la diagnostica di mypy con il TypeError di Python. Traccia quindi la gestione delle chiamate **a e delle chiavi TypedDict, poi aggiungi la copertura che dimostri che l'argomento mancante è foo anziché bar.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 50/100