Mypy not reporting "undefined" variable.
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
Bug Report
When using a "undefined" variable, which will immediately crash the code when running it, mypy does not report anything about it. Is it normal ?
I feel like mypy should report it but maybe I am wrong because this isn't a typing error. On the other hand, this error is only possible because typing annotations exist . What do you think ?
To Reproduce
Dump this in a file main.py:
number: int
print(number)
Gist URL: https://gist.github.com/mypy-play/31d3775229a6fe01af6bbb09b9230a18
Playground URL: https://mypy-play.net/?mypy=latest&python=3.11&gist=31d3775229a6fe01af6bbb09b9230a18
Expected Behavior
An error message, maybe something like this.
main.py:2: error: Using an undefined variable, a value must be set before first. [var-undefined]
Actual Behavior
$ mypy --strict main.py
Success: no issues found in 1 source file
python main.py
Traceback (most recent call last):
File "/home/user/main.py", line 2, in <module>
print(number)
^^^^^^
NameError: name 'number' is not defined
Your Environment
- Mypy version used: 1.3.0
- Mypy command-line flags: --strict
- Mypy configuration options from
mypy.ini(and other config files): nothing - Python version used: 3.11.3
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
Comienza reproduciendo el comportamiento con el ejemplo main.py y mypy --strict main.py. Revisa cómo gestiona el checker una variable que solo tiene una anotación antes de decidir si este caso debería recibir un diagnóstico como [var-undefined]. La tarea está terminada cuando el comportamiento está cubierto por una prueba y un diagnóstico adecuados, o cuando el comportamiento esperado está documentado como no compatible.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100