TypedDict item insertion support
Aperta
Nessuno ha ancora preso questa issue.
feature
priority-1-normal
topic-typed-dict
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
- 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
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 l’esempio TypedDict fornito con la versione corrente di mypy e analizzando come vengono verificate le espressioni delle chiavi TypedDict. Il lavoro è completato quando i controlli espliciti che limitano una chiave ai nomi TypedDict validi consentono le assegnazioni mostrate senza errori, mentre le chiavi non valide continuano a essere rifiutate; aggiungi o aggiorna test mirati per entrambi i casi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100