Open
Description
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'