Support for default types in TypedDict
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
El issue describe la ampliación de TypedDict con un tipo de valor predeterminado para claves que, de otro modo, serían desconocidas, usando el ejemplo de WSGI environ como motivación. Empieza revisando el soporte existente de TypedDict en mypy y sus pruebas; se considerará terminado cuando la sintaxis propuesta esté definida, las claves arbitrarias reciban el tipo predeterminado, las claves explícitas conserven sus tipos y el comportamiento esté cubierto por pruebas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100