Disallow assignment of `Any` to known/explicit types and/or Introduce `Unknown` type
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
Feature
I'd like an option that prevents assigned of the Any type to something with a known type, in particular places where I've specified the type.
Returns:
def return_type_a() -> TypeA:
untyped = {}
return untype # Disallow
Assignement:
store : Dict[StoreRef,StoreItem = {}
def create() -> Dict:
return {}
store = create() # Disallow
Pitch
It'd be nice to have a stricter boundary between typed and untyped code. The samples I show above are frequent sources of error for me and they quietly slip by the type checking.
While migrated code there are still a lot of Any's in the code, and in some domains they'll never go away (when dealing with genuinely generic data structures, also now since some recrusive types, like JSON, need to use Any).
Related
An explicit Unknown type, in contrast to Any, would also help a lot. TypeScript has an unknown and it is helpful for dealing with generic data and not accidentally using it as the wrong type.
If an Unknown was available the above could also be achieved by turning on the "disallow any" flags and using Unknown in places where generic data is needed.
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
Empieza leyendo cómo mypy maneja Any y sus flags disallow-any existentes, usando los ejemplos de retorno y asignación como casos de comportamiento. Aclara si el trabajo abarca comprobaciones de asignación más estrictas, un tipo Unknown o ambos; se considera terminado cuando el comportamiento seleccionado está especificado y se aplica sin romper el uso legítimo de datos genéricos.
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
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100