TypedDict item insertion support
Offen
Dieses Issue hat noch niemand übernommen.
feature
priority-1-normal
topic-typed-dict
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
- Are you reporting a bug, or opening a feature request?
Feature request - Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
Currently I can't insert items into TypedDict even after explicit check for a defined key:
from mypy_extensions import TypedDict
GroupDataDict = TypedDict(
'GroupDataDict', {"children": str,
"vars": str,
"hosts": str}, total=False
)
test_group: GroupDataDict = {}
key = "children"
if key in ("children", "vars"):
test_group[key] = "a"
if key not in ["children", "vars"]:
raise ValueError("")
test_group[key] = "b"
print(test_group)
- What is the actual behavior/output?
-> % mypy typeddict_insertion.py
typeddict_insertion.py:12: error: TypedDict key must be a string literal; expected one of ('children', 'vars', 'hosts')
typeddict_insertion.py:16: error: TypedDict key must be a string literal; expected one of ('children', 'vars', 'hosts')
- What is the behavior/output you expect?
No error - What are the versions of mypy and Python you are using?
mypy 0.620 + Python 3.7 - Do you see the same issue after installing mypy from Git master?
I haven't tried - What are the mypy flags you are using? (For example --strict-optional)
[mypy]
python_version = 3.7
check_untyped_defs = True
disallow_any_generics = True
disallow_untyped_calls = True
ignore_errors = False
ignore_missing_imports = True
strict_optional = True
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
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, das bereitgestellte TypedDict-Beispiel mit der aktuellen mypy-Version auszuführen und zu untersuchen, wie Ausdrücke für TypedDict-Schlüssel geprüft werden. Die Arbeit ist abgeschlossen, wenn explizite Prüfungen, die einen Schlüssel auf gültige TypedDict-Namen beschränken, die gezeigten Zuweisungen ohne Fehler zulassen, während ungültige Schlüssel weiterhin abgelehnt werden; füge fokussierte Tests für beide Fälle hinzu oder aktualisiere sie.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100