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