-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wronggood-second-issuepriority-2-lowtopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctlytopic-variable-scope
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) # Incorrectly reveals int, should be Optional[int]
reveal_type(y) # Correctly reveals int
x = 2
I also found https://bugs.python.org/issue24129 interesting. Thanks, ilevkivskyi!
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wronggood-second-issuepriority-2-lowtopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctlytopic-variable-scope