Title: False positive `statement is unreachable` in try-finally related to KeyboardInterrupt · Issue #13104 · python/mypy · GitHub
Open Graph Title: False positive `statement is unreachable` in try-finally related to KeyboardInterrupt · Issue #13104 · python/mypy
X Title: False positive `statement is unreachable` in try-finally related to KeyboardInterrupt · Issue #13104 · python/mypy
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] = Non...
Open Graph 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. ...
X 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. ...
Opengraph URL: https://github.com/python/mypy/issues/13104
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive `statement is unreachable` in try-finally related to KeyboardInterrupt","articleBody":"**Bug Report**\r\n\r\nA `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.\r\n\r\n```python3\r\ndef fn() -\u003e None:\r\n i: Optional[int] = None\r\n try:\r\n i = 1\r\n finally:\r\n if i is None:\r\n return # error: Statement is unreachable\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nIt's trivial to show that this statement is reachable. Insert a `sleep` before the assignment:\r\n\r\n```python3\r\ndef fn() -\u003e None:\r\n i: Optional[int] = None\r\n try:\r\n time.sleep(10)\r\n i = 1\r\n finally:\r\n if i is None:\r\n print(\"reachable\")\r\n return\r\n```\r\n\r\nAnd then Ctrl+C (`KeyboardInterrupt`) the function during its execution. The `print` will run.\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.960\r\n- Mypy command-line flags: `--warn-unreachable` seems to be the only flag necessary to reproduce this\r\n\r\n","author":{"url":"https://github.com/bbatliner","@type":"Person","name":"bbatliner"},"datePublished":"2022-07-11T18:41:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/13104/mypy/issues/13104"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a17f112d-6917-71f3-7c0e-58a3eb221a34 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B684:29ED0C:D6BABC:11B231E:6A5BBAAB |
| html-safe-nonce | ad93f95d70f521b892568da436cf921a8f299cfd37a825c72a05c8e34e04af2c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjg0OjI5RUQwQzpENkJBQkM6MTFCMjMxRTo2QTVCQkFBQiIsInZpc2l0b3JfaWQiOiI1MjY2MDE5MDc3OTYyMDU0MzE1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 45af4b4e237c6d29a095a506b35e7f12595813023e5dd33e7b127191c70a42ca |
| hovercard-subject-tag | issue:1301083227 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/13104/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dbddd721993c49f3fc261f234636fe87d5f79be56c82b6d4f24d69ebf3a1dd4a/python/mypy/issues/13104 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dbddd721993c49f3fc261f234636fe87d5f79be56c82b6d4f24d69ebf3a1dd4a/python/mypy/issues/13104 |
| og:image:alt | 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. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bbatliner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width