Title: Flag `None` check on value that cannot be `None` · Issue #18386 · python/mypy · GitHub
Open Graph Title: Flag `None` check on value that cannot be `None` · Issue #18386 · python/mypy
X Title: Flag `None` check on value that cannot be `None` · Issue #18386 · python/mypy
Description: Say I have function that maybe returns None and I check the result: def f() -> int | None: ... if f() is None: ... I rewrite the function so that it never returns None: def f() -> int: ... if f() is None: ... Now the is None check makes ...
Open Graph Description: Say I have function that maybe returns None and I check the result: def f() -> int | None: ... if f() is None: ... I rewrite the function so that it never returns None: def f() -> int: ... if f() i...
X Description: Say I have function that maybe returns None and I check the result: def f() -> int | None: ... if f() is None: ... I rewrite the function so that it never returns None: def f() -> int: ... if...
Opengraph URL: https://github.com/python/mypy/issues/18386
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Flag `None` check on value that cannot be `None`","articleBody":"Say I have function that maybe returns `None` and I check the result:\r\n\r\n```python\r\ndef f() -> int | None: ...\r\n\r\nif f() is None: ...\r\n```\r\n\r\nI rewrite the function so that it never returns `None`:\r\n\r\n```python\r\ndef f() -> int: ...\r\n\r\nif f() is None: ...\r\n```\r\n\r\nNow the `is None` check makes no sense -- it will always fail. This is a mistake introduced in refactoring and it should be flagged. (And similar for `is not None` checks)\r\n\r\nIn Rust I don't think this kind of error is possible:\r\n\r\n```rust\r\nfn f() -> Option\u003cu8>;\r\n\r\nif f().is_none() {} // okay\r\n\r\nfn g() -> u8;\r\n\r\nif g().is_none() {} // no good\r\n```","author":{"url":"https://github.com/nickdrozd","@type":"Person","name":"nickdrozd"},"datePublished":"2024-12-30T21:28:44Z","url":"https://github.com/python/mypy/issues/18386"}
| 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:d70e686e-c583-f955-7376-0c07a741e808 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A168:B7CF9:64B2E6:8665D3:6B003450 |
| html-safe-nonce | aa8c6c28eb9c4d7864b2f3a8d137dd1b8ce96d7e62c02d003c89b4ff18d97423 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTY4OkI3Q0Y5OjY0QjJFNjo4NjY1RDM6NkIwMDM0NTAiLCJ2aXNpdG9yX2lkIjoiODcwNzI2Njg3NjkxNDI4MzYwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4a09da39ee572d877eddf7bab4622ae92317acec32663f024ea315c6148e4f2c |
| hovercard-subject-tag | issue:2763716067 |
| 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/18386/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fde2c232038af4c7f08a32b29af78d8cda897a3a846d40677cc8743e7f8e885f/python/mypy/issues/18386 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fde2c232038af4c7f08a32b29af78d8cda897a3a846d40677cc8743e7f8e885f/python/mypy/issues/18386 |
| og:image:alt | Say I have function that maybe returns None and I check the result: def f() -> int | None: ... if f() is None: ... I rewrite the function so that it never returns None: def f() -> int: ... if f() i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nickdrozd |
| 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