Open
Description
Example courtesy of @gvanrossum , based on https://twitter.com/gvanrossum/status/1354305179244392453
While Python's behaviour is surprising, mypy should match it.
from typing import *
x: Optional[int] = None
y: Optional[int] = None
def f() -> None:
x = 1
y = 1
class C:
reveal_type(x) # Correctly reveals int
reveal_type(y) # Incorrectly reveals int, should be Optional[int]
x = 2
I also found https://bugs.python.org/issue24129 interesting. Thanks, ilevkivskyi!