Redefinition without reassignment doesn't check existing value
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
With --allow-redefinition, mypy allows a variable to be redefined, without checking that the existing value is the correct type.
a: str = "foo"
print(a) # value needs to be used before redefinition
a: int # but it is really still str
if a > 1:
...
Expected Behaviour
In this example, mypy should detect that a is still a str, and not allow this redefinition.
It could treat the redefinition as though it is a new variable, being assigned the value of the existing one. That would result in an error like:
error: Incompatible types in assignment (expression has type "str", variable has type "int")
Or it could be a new error, like:
error: Redefinition incompatible with existing type (existing type "str", new type "int")
Actual Behaviour
mypy:
Success: no issues found in 1 source file
python:
TypeError: '>' not supported between instances of 'str' and 'int'
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 ejemplo de la ejecución vinculada de mypy-play.net con --allow-redefinition y, después, sigue el procesamiento que hace mypy de las redefiniciones anotadas. El trabajo estará terminado cuando el valor str existente se compruebe con la anotación int posterior y mypy informe de un error apropiado en lugar de indicar éxito.
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
- 35/100