Title: False positives with `--strict-optional` turned off · Issue #2999 · python/mypy · GitHub
Open Graph Title: False positives with `--strict-optional` turned off · Issue #2999 · python/mypy
X Title: False positives with `--strict-optional` turned off · Issue #2999 · python/mypy
Description: This is a low-priority issue (or maybe should even be closed), just wanted to add it for the record in case others run into it. When --strict-optional is turned off, mypy in some cases is unable to infer the correct type inside ... if No...
Open Graph Description: This is a low-priority issue (or maybe should even be closed), just wanted to add it for the record in case others run into it. When --strict-optional is turned off, mypy in some cases is unable to...
X Description: This is a low-priority issue (or maybe should even be closed), just wanted to add it for the record in case others run into it. When --strict-optional is turned off, mypy in some cases is unable to...
Opengraph URL: https://github.com/python/mypy/issues/2999
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positives with `--strict-optional` turned off","articleBody":"This is a low-priority issue (or maybe should even be closed), just wanted to add it for the record in case others run into it.\r\n\r\nWhen `--strict-optional` is turned off, mypy in some cases is unable to infer the correct type inside `... if None else ...` type conditionals; this doesn't happen always, only if it's preceded with `assert isinstance(x, (X, type(None)))` when `x` was known to be of type `Base`, which is the base class of `X`:\r\n\r\n```\r\nfrom typing import *\r\n\r\nclass A:\r\n a = 1\r\n\r\nclass B(A):\r\n b = 2\r\n\r\ndef f(x: Union[A, None]) -> None:\r\n assert isinstance(x, (B, type(None)))\r\n y = x.b if x is not None else x # fails type check if --strict-optional is off, passes otherwise\r\n```\r\n\r\nThe fix would be messy (mypy correctly analyzes the `if` statement, the problem is that it ignores the `isinstance` because it thinks that the assertion always succeeds anyway due to some problem with `None` handling).","author":{"url":"https://github.com/pkch","@type":"Person","name":"pkch"},"datePublished":"2017-03-14T18:32:34Z","url":"https://github.com/python/mypy/issues/2999"}
| 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:380d921e-56e9-7d9b-5590-cf5c2f20ca60 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C52E:59847:208731:2BEC85:6B0022AC |
| html-safe-nonce | 3127dfd268990f40b6532bdcfebe06955f0e1c85f71eacc68ba8b86e4cf35222 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTJFOjU5ODQ3OjIwODczMToyQkVDODU6NkIwMDIyQUMiLCJ2aXNpdG9yX2lkIjoiOTk3NzE5OTk4NDE3ODcxNTMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0db9f69745cad5384e6ae4566bb9677963caee5f1c0f533ff9b33abd9687fcd4 |
| hovercard-subject-tag | issue:214166564 |
| 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/2999/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b9598d99848acd87b405fd7446669a2132d66ec16a10301084260fbda6bb3f9b/python/mypy/issues/2999 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b9598d99848acd87b405fd7446669a2132d66ec16a10301084260fbda6bb3f9b/python/mypy/issues/2999 |
| og:image:alt | This is a low-priority issue (or maybe should even be closed), just wanted to add it for the record in case others run into it. When --strict-optional is turned off, mypy in some cases is unable to... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pkch |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width