mypy flags "overlap between argument names and ** TypedDict items" with total=False
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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.
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
Beginnen Sie mit dem minimalen Reproducer in main.py oder führen Sie ihn im verknüpften mypy playground aus und bestätigen Sie die Überlappungsdiagnose in Zeile 9. Verfolgen Sie den Einstiegspunkt der mypy-Typprüfung, der für ein Unpack’ed total=False TypedDict „Overlap between argument names and ** TypedDict items“ meldet. Als erledigt gilt die Aufgabe, wenn der Reproducer diesen Fehler nicht mehr meldet, während das übrige Typverhalten weiterhin geprüft wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 52/100