When using`--disallow-any-expr`, silence complaints about Any where object would work
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
Problem
Using Any is not type safe, therefore Mypy provides options to disallow Any. However, there are many uses of Any from third-party and stdlib, so these options tend to result in a lot of errors even when they are not relevant.
I'm finding many situations where I get an error about Any, but the code would be deemed safe if it was object.
Examples
This produces errors about Any on both lines even though the value is not used:
type_hints = typing.get_type_hints(...) # Dict[str, Any]
if k in type_hints:
...
This produces errors as well, but object would not produce errors, as Mypy can infer everything necessary here to be type safe.
origin = typing.get_origin(...) # Any
if origin is Literal:
...
elif origin is list:
...
Solution
Add an option, or change the behaviour of the current disallow Any options, such that Any is treated like object. Then, rather than producing errors when Any is present, just show normal errors with Any (as if it was object) in them (e.g. 'Any has no attribute foo').
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 reproduciendo los dos ejemplos con --disallow-any-expr y compara sus diagnósticos con anotaciones object equivalentes. Revisa el manejo existente de las opciones disallow-Any y, después, define pruebas para tratar Any como object, conservando al mismo tiempo los errores ordinarios, como los atributos ausentes.
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
- 35/100