Title: Don't complain about missing return with `Optional[
Open Graph Title: Don't complain about missing return with `Optional[
X Title: Don't complain about missing return with `Optional[
Description: from typing import Optional def s(e: int) -> Optional[int]: if e > 2: return 4 s(2) Currently mypy complains about missing return here and adding return None in the end of the function fixes that. However I think that's undesirable: It's...
Open Graph Description: from typing import Optional def s(e: int) -> Optional[int]: if e > 2: return 4 s(2) Currently mypy complains about missing return here and adding return None in the end of the function fixes that. ...
X Description: from typing import Optional def s(e: int) -> Optional[int]: if e > 2: return 4 s(2) Currently mypy complains about missing return here and adding return None in the end of the function fixes ...
Opengraph URL: https://github.com/python/mypy/issues/3974
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Don't complain about missing return with `Optional[\u003ctype>]`","articleBody":"```python\r\nfrom typing import Optional\r\n\r\ndef s(e: int) -> Optional[int]:\r\n if e > 2:\r\n return 4\r\n\r\ns(2)\r\n```\r\n\r\nCurrently mypy complains about missing return here and adding `return None` in the end of the function fixes that. However I think that's undesirable:\r\n\r\n* It's not actually catching a bug: it's a false positive. False positives are bad as they lead to lost time and confusion\r\n* It motivates people to put a useless `return None` line (even `return` doesn't work) which is just noise in the program code in this case\r\n* It invalidates core Python behavior: since the dawn of time, no return, `return` and `return None` mean absolutely the same in each function, but mypy only recognizes one of those forms in this case.\r\n\r\nObviously that seems like a simple example, but I have a longer if/elif function where mypy just says `missing return on \u003cfirst line of function>` which has two issues : it's not a type bug, and mypy doesn't the invalid branch\r\n\r\n","author":{"url":"https://github.com/alehander92","@type":"Person","name":"alehander92"},"datePublished":"2017-09-20T16:17:36Z","url":"https://github.com/python/mypy/issues/3974"}
| 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:48f13ada-bb12-017d-9d78-854f1ccf04a5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82B2:1D865F:55B40F:74F4F9:6B007364 |
| html-safe-nonce | 6cb4187092c10d6fc260d8ff07ab369bd8b8c4f0c3410c0ea383c6de25c50c70 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkIyOjFEODY1Rjo1NUI0MEY6NzRGNEY5OjZCMDA3MzY0IiwidmlzaXRvcl9pZCI6IjM2NDQ3MDIyNDQwODkxMzE4NzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e6b4d61f340fe90d28514575025989fd87c36a9041937583657e2bfa840f3c36 |
| hovercard-subject-tag | issue:259222218 |
| 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/3974/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b88c11acb84e22e46559bf94033dab7e67f74b401ba6d80a0d1c2c67da9cf3b0/python/mypy/issues/3974 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b88c11acb84e22e46559bf94033dab7e67f74b401ba6d80a0d1c2c67da9cf3b0/python/mypy/issues/3974 |
| og:image:alt | from typing import Optional def s(e: int) -> Optional[int]: if e > 2: return 4 s(2) Currently mypy complains about missing return here and adding return None in the end of the function fixes that. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alehander92 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 75c2b65dd205f26961d0c29afed1a8d0bb7cca9f05780571dfd1ef93eb539d16 |
| 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 | 84e563eb4b55f8fa102f325f117533cee9e3df4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width