Title: under some conditions mypy thinks a function that always calls sys.exit() returns · Issue #14025 · python/mypy · GitHub
Open Graph Title: under some conditions mypy thinks a function that always calls sys.exit() returns · Issue #14025 · python/mypy
X Title: under some conditions mypy thinks a function that always calls sys.exit() returns · Issue #14025 · python/mypy
Description: Bug Report I managed to make mypy think error in the following has implicit return, changing pretty much anything makes it work correctly: moving definition of the class C before that of error removing the use of field declared in __init...
Open Graph Description: Bug Report I managed to make mypy think error in the following has implicit return, changing pretty much anything makes it work correctly: moving definition of the class C before that of error remo...
X Description: Bug Report I managed to make mypy think error in the following has implicit return, changing pretty much anything makes it work correctly: moving definition of the class C before that of error remo...
Opengraph URL: https://github.com/python/mypy/issues/14025
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"under some conditions mypy thinks a function that always calls sys.exit() returns","articleBody":"\r\n\r\n**Bug Report**\r\n\r\nI managed to make mypy think `error` in the following has implicit return, changing pretty much anything makes it work correctly:\r\n\r\n * moving definition of the class C before that of error\r\n * removing the use of field declared in `__init__`, even if there's other code there\r\n * adding a declaration of `x` within class body\r\n * moving the call to `sys.exit()` before first use of `x`\r\n * throwing an exception instead of calling `sys.exit()`\r\n\r\nAnd I couldn't make similar code fail in any way when the function returns something. Swapping `\"C\"` with `C` doesn't fix anything either of course.\r\n\r\n**To Reproduce**\r\n\r\nCode with (most of) the changes mentioned above commented out:\r\n\r\n```python\r\nimport sys\r\nfrom typing import NoReturn\r\n\r\n\r\n# def error(c: \"C\") -> int:\r\ndef error(c: \"C\") -> NoReturn:\r\n x = c.x\r\n # x = 2 + 2\r\n\r\n sys.exit(1)\r\n # raise Exception()\r\n # return x\r\n\r\n\r\nclass C:\r\n # x: int\r\n\r\n def __init__(self, x: int):\r\n self.x = x\r\n```\r\n\r\nTried it after deleting caches and with `--no-incremental` and it still bugs out. (though i definitely didn't bisect all working cases like that)\r\n\r\n**Expected Behavior**\r\n\r\nIt sees that `error` doesn't return, as in all other variants.\r\n\r\n**Actual Behavior**\r\n\r\n\u003c!-- What went wrong? Paste mypy's output. -->\r\n\r\n```\r\nbug.py:6: error: Implicit return in function which does not return\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: 0.982\r\n- Mypy command-line flags: with and without --strict, with and without --incremental\r\n- Mypy configuration options from `mypy.ini` (and other config files): none\r\n- Python version used: 3.10.8\r\n\r\n\u003c!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->\r\n","author":{"url":"https://github.com/phaker","@type":"Person","name":"phaker"},"datePublished":"2022-11-07T17:24:42Z","url":"https://github.com/python/mypy/issues/14025"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:30a9b997-eed4-dc55-e5e3-8c5636866970 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7C4:390AA2:22E7861:2F8D4F7:6B002A14 |
| html-safe-nonce | 0057956117fcfed9dda507d76c5c7f404ed1dc7445ef929b911e8c6323ebd42b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0M0OjM5MEFBMjoyMkU3ODYxOjJGOEQ0Rjc6NkIwMDJBMTQiLCJ2aXNpdG9yX2lkIjoiNTU3ODIyMDA3ODkyMDM3ODkwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ae96161705f3c3d8c61fd92a7dbb089c46fb36f41e64f6237c5ecad9cc8180bb |
| hovercard-subject-tag | issue:1438718745 |
| 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/14025/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7d2171a185c4bc612a2ad5f49aefc58388f652c0acb7440533d1dc21d0e821f8/python/mypy/issues/14025 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7d2171a185c4bc612a2ad5f49aefc58388f652c0acb7440533d1dc21d0e821f8/python/mypy/issues/14025 |
| og:image:alt | Bug Report I managed to make mypy think error in the following has implicit return, changing pretty much anything makes it work correctly: moving definition of the class C before that of error remo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | phaker |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width