Title: warn_no_return = False: handle implicit "return None" (not ignoring return type) · Issue #7511 · python/mypy · GitHub
Open Graph Title: warn_no_return = False: handle implicit "return None" (not ignoring return type) · Issue #7511 · python/mypy
X Title: warn_no_return = False: handle implicit "return None" (not ignoring return type) · Issue #7511 · python/mypy
Description: warn_no_return is on by default, but does not take into account that None is returned explicitly. I think it should maybe only warn if the return type does not include None (i.e. uses typing.Optional). Given t_mypy.py: import typing def ...
Open Graph Description: warn_no_return is on by default, but does not take into account that None is returned explicitly. I think it should maybe only warn if the return type does not include None (i.e. uses typing.Option...
X Description: warn_no_return is on by default, but does not take into account that None is returned explicitly. I think it should maybe only warn if the return type does not include None (i.e. uses typing.Option...
Opengraph URL: https://github.com/python/mypy/issues/7511
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"warn_no_return = False: handle implicit \"return None\" (not ignoring return type)","articleBody":"`warn_no_return` is on by default, but does not take into account that `None` is returned explicitly.\r\n\r\nI think it should maybe only warn if the return type does not include `None` (i.e. uses `typing.Optional`).\r\n\r\nGiven t_mypy.py:\r\n\r\n```python\r\nimport typing\r\n\r\n\r\ndef no_return_optional(arg) -> typing.Optional[str]:\r\n if arg:\r\n return \"false\"\r\n\r\n\r\ndef no_return(arg) -> str:\r\n if arg:\r\n return \"false\"\r\n\r\n\r\na1 = no_return_optional(True)\r\na2 = no_return_optional(False)\r\nreveal_type(a1)\r\nreveal_type(a2)\r\n\r\nb1 = no_return(True)\r\nb2 = no_return(False)\r\nreveal_type(b1)\r\nreveal_type(b2)\r\n```\r\n\r\n`mypy --warn-no-return` shows:\r\n\r\n```\r\nt_mypy.py:4: error: Missing return statement\r\nt_mypy.py:9: error: Missing return statement\r\nt_mypy.py:16: note: Revealed type is 'Union[builtins.str, None]'\r\nt_mypy.py:17: note: Revealed type is 'Union[builtins.str, None]'\r\nt_mypy.py:21: note: Revealed type is 'builtins.str'\r\nt_mypy.py:22: note: Revealed type is 'builtins.str'\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n\r\n`mypy --no-warn-no-return` does not show any error, but should warn/error about the missing return statement / wrong return value for `no_return` (which is annotated to return `str`, but might return `None`).\r\n\r\nmypy 0.730+dev.28423cd78062b81365ec9aaa591b4e823af1606d","author":{"url":"https://github.com/blueyed","@type":"Person","name":"blueyed"},"datePublished":"2019-09-13T22:19:50Z","url":"https://github.com/python/mypy/issues/7511"}
| 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:31499ff6-1913-e353-0e4f-b7691f46bdf5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CBCC:106F5D:FC67D9:153CB12:6B005E14 |
| html-safe-nonce | 140e73bcc1aa30eff3d32d12c3b1bfb2a648cc27b5d7d8a56575646722af3d8e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkNDOjEwNkY1RDpGQzY3RDk6MTUzQ0IxMjo2QjAwNUUxNCIsInZpc2l0b3JfaWQiOiIzMzgwODM4ODQwOTA1MjYwNTY0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 33d6237fb91882bf0221bec0b6f1e6a2c40511943787a20c57f1f8a967b54c92 |
| hovercard-subject-tag | issue:493538094 |
| 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/7511/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0911f57cb1bf62da8bc3826ea9a71c77e97ea5ffa1db2414ff10da30c2bd40a2/python/mypy/issues/7511 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0911f57cb1bf62da8bc3826ea9a71c77e97ea5ffa1db2414ff10da30c2bd40a2/python/mypy/issues/7511 |
| og:image:alt | warn_no_return is on by default, but does not take into account that None is returned explicitly. I think it should maybe only warn if the return type does not include None (i.e. uses typing.Option... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | blueyed |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| 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 | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width