Mypy infers the type Any for y after the second assignment:
from typing import Any
def f(x: Any) -> None:
y = x
y = 1
reveal_type(y) # Any
Inferring int as the type might be less surprising. However, if a variable is explicitly declared with an Any type, such as x in the above example, it's less clear what would be the right thing to do.
A more general solution would allow redefining variables with arbitrary new types (#1174).
Mypy infers the type
Anyforyafter the second assignment:Inferring
intas the type might be less surprising. However, if a variable is explicitly declared with anAnytype, such asxin the above example, it's less clear what would be the right thing to do.A more general solution would allow redefining variables with arbitrary new types (#1174).