-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Closed
Copy link
Labels
bugmypy got something wrongmypy got something wrongtopic-reachabilityDetecting unreachable codeDetecting unreachable code
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 unreachableExpected 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")
returnAnd 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-unreachableseems to be the only flag necessary to reproduce this
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-reachabilityDetecting unreachable codeDetecting unreachable code