-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normalsemantic-analyzerProblems that happen during semantic analysisProblems that happen during semantic analysistopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctlytopic-variable-scope
Description
$ cat santa/scheduler/loop.py
import signal
from typing import Any
def loop() -> None:
def signal_handler(signum: Any, frame: Any) -> None:
nonlocal running
running = False
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
running = True
while running:
pass
$ mypy --new-semantic-analyzer santa/scheduler/loop.py
santa/scheduler/loop.py:7: error: No binding for nonlocal 'running' found
This code passes under the old semantic analyzer. The error goes away if I move the running = True
line above the definition of the nested function.
It doesn't seem unreasonable to me to require that the definition of a variable is lexically before its use as a nonlocal, so maybe this doesn't need to be fixed.
sush-abc, khyox, akhan3, thisisrahul and Dharmikas
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normalsemantic-analyzerProblems that happen during semantic analysisProblems that happen during semantic analysistopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctlytopic-variable-scope