Incorrect error when argument missing from function call unpacking 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
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'
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, den bereitgestellten mypy-play TypedDict- und function-unpacking-Reproduzierer auszuführen und mypys Diagnose mit Pythons TypeError zu vergleichen. Verfolge dann die Behandlung von **a-Aufrufen und TypedDict-Schlüsseln und füge anschließend Abdeckung hinzu, die zeigt, dass das fehlende Argument foo und nicht bar ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 50/100