You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive statement is unreachable in try-finally related to KeyboardInterrupt #13104
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.
Activity
bbatliner commentedon Jul 11, 2022
Technically any exception could be raised before the statements inside of the
tryblock execute, not justKeyboardInterrupt, via CPython's asynchronous exception state that each thread tracks: https://docs.python.org/3/c-api/init.html#c.PyThreadState_SetAsyncExcbbatliner commentedon Jul 11, 2022
What makes this extra interesting is that the unreachable block appears necessary to narrow the Optional and avoid an attribute error:
whereas such narrowing is implicit without the try-finally:
tyralla commentedon Jul 20, 2025
Fixed by #19270; included in Mypy 1.17.