Open
Description
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).