Support for default types in 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
This problem arose from trying to type the environ argument for a WSGI application. There are specific keys of the environ dict that have non-str types, and then all the other keys are HTTP_ variables (or server-defined variables, which can be ignored for this purpose) with type str (or Text, depending on the version of Python).
I would like to get stronger typing on environ than Dict[str, Any], but there isn't a way to do that with TypedDict currently because the set of possible keys is unbounded (the client can send any HTTP header).
Ideally, I'd like to be able to do something like:
EnvironDict = TypedDict("EnvironDict", {
"wsgi.version": Tuple[int, int],
"wsgi.input": IO[str],
# ...
}, default_type=str, total=False)
and have this mean that any key is allowed in the dictionary and all unknown keys get a value type of str.
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
L’issue descrive l’estensione di TypedDict con un tipo di valore predefinito per le chiavi altrimenti sconosciute, usando l’esempio di WSGI environ come motivazione. Inizia esaminando il supporto esistente di TypedDict in mypy e i relativi test; il lavoro sarà completato quando la sintassi proposta sarà definita, le chiavi arbitrarie riceveranno il tipo predefinito, le chiavi esplicite manterranno i propri tipi e il comportamento sarà coperto dai test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100