Open
Description
Bug Report
A KeyboardInterrupt
may interleave between the start of a try
block and its contained statements. mypy
seems to assume that the flow of execution will not be asynchronously interrupted.
def fn() -> None:
i: Optional[int] = None
try:
i = 1
finally:
if i is None:
return # error: Statement is unreachable
Expected Behavior
It's trivial to show that this statement is reachable. Insert a sleep
before the assignment:
def fn() -> None:
i: Optional[int] = None
try:
time.sleep(10)
i = 1
finally:
if i is None:
print("reachable")
return
And then Ctrl+C (KeyboardInterrupt
) the function during its execution. The print
will run.
Your Environment
- Mypy version used: 0.960
- Mypy command-line flags:
--warn-unreachable
seems to be the only flag necessary to reproduce this