Title: Feature requests: recognise that some types always evaluate to False · Issue #8692 · python/mypy · GitHub
Open Graph Title: Feature requests: recognise that some types always evaluate to False · Issue #8692 · python/mypy
X Title: Feature requests: recognise that some types always evaluate to False · Issue #8692 · python/mypy
Description: Are you reporting a bug, or opening a feature request? Feature Request Please insert below the code you are checking with mypy, import typing as t class NotPresent: def __bool__(self) -> t.Literal[False]: return False x: t.Union[NotPrese...
Open Graph Description: Are you reporting a bug, or opening a feature request? Feature Request Please insert below the code you are checking with mypy, import typing as t class NotPresent: def __bool__(self) -> t.Literal[...
X Description: Are you reporting a bug, or opening a feature request? Feature Request Please insert below the code you are checking with mypy, import typing as t class NotPresent: def __bool__(self) -> t.Liter...
Opengraph URL: https://github.com/python/mypy/issues/8692
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature requests: recognise that some types always evaluate to False","articleBody":"* Are you reporting a bug, or opening a feature request?\r\nFeature Request\r\n* Please insert below the code you are checking with mypy,\r\n```\r\nimport typing as t\r\n\r\n\r\nclass NotPresent:\r\n def __bool__(self) -> t.Literal[False]:\r\n return False\r\n\r\n\r\nx: t.Union[NotPresent, t.Sequence[int]] = [1]\r\nreveal_type(x)\r\nif x:\r\n print(x[0])\r\n```\r\n* What is the actual behavior/output?\r\n`test.py:12:11: error: Value of type \"Union[NotPresent, Sequence[int]]\" is not indexable`\r\n* What is the behavior/output you expect?\r\nThe `if x` branch should recognise that x cannot be of type `NotPresent` (as it would do if it was `None` rather than `NotPresent`)\r\n\r\n* What are the versions of mypy and Python you are using?\r\n0.770 & master\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\nNone\r\n","author":{"url":"https://github.com/reinhrst","@type":"Person","name":"reinhrst"},"datePublished":"2020-04-17T22:10:18Z","url":"https://github.com/python/mypy/issues/8692"}
| 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:b6375be5-fedd-5cf3-32ad-404136fbed32 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C39A:390AA2:23FD599:310B708:6B002FD0 |
| html-safe-nonce | 243a3e146fbc529b4e76b286ff1a263d89303ad4ba2e9509d73fef9c06633355 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzlBOjM5MEFBMjoyM0ZENTk5OjMxMEI3MDg6NkIwMDJGRDAiLCJ2aXNpdG9yX2lkIjoiMjUxNDQ5OTg2NjY0MjYyNDQ2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a797eae6d06046864c929062fa5ca114e8875992e4ede25c0ea3d12951230a89 |
| hovercard-subject-tag | issue:602260498 |
| 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/8692/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9110f8b0afa6fca9ce1aa8c4111e1a8f1fb0dc2ba3ccf22000f718461b0d1ec9/python/mypy/issues/8692 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9110f8b0afa6fca9ce1aa8c4111e1a8f1fb0dc2ba3ccf22000f718461b0d1ec9/python/mypy/issues/8692 |
| og:image:alt | Are you reporting a bug, or opening a feature request? Feature Request Please insert below the code you are checking with mypy, import typing as t class NotPresent: def __bool__(self) -> t.Literal[... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | reinhrst |
| 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