Title: Support exhaustiveness checking for 'in' statements (enums) · Issue #16093 · python/mypy · GitHub
Open Graph Title: Support exhaustiveness checking for 'in' statements (enums) · Issue #16093 · python/mypy
X Title: Support exhaustiveness checking for 'in' statements (enums) · Issue #16093 · python/mypy
Description: Feature Allow the use of the in statement when doing exhaustiveness checking. from enum import Enum from typing import assert_never class MyEnum(Enum): A = 1 B = 2 C = 3 def my_function(a: MyEnum) -> bool: if a == MyEnum.A: return True e...
Open Graph Description: Feature Allow the use of the in statement when doing exhaustiveness checking. from enum import Enum from typing import assert_never class MyEnum(Enum): A = 1 B = 2 C = 3 def my_function(a: MyEnum) ...
X Description: Feature Allow the use of the in statement when doing exhaustiveness checking. from enum import Enum from typing import assert_never class MyEnum(Enum): A = 1 B = 2 C = 3 def my_function(a: MyEnum) ...
Opengraph URL: https://github.com/python/mypy/issues/16093
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support exhaustiveness checking for 'in' statements (enums)","articleBody":"**Feature**\r\n\r\nAllow the use of the `in` statement when doing exhaustiveness checking.\r\n\r\n```python\r\nfrom enum import Enum\r\nfrom typing import assert_never\r\n\r\n\r\nclass MyEnum(Enum):\r\n A = 1\r\n B = 2\r\n C = 3 \r\n\r\n\r\ndef my_function(a: MyEnum) -> bool:\r\n if a == MyEnum.A:\r\n return True\r\n elif a in (MyEnum.B, MyEnum.C):\r\n return False\r\n assert_never(a)\r\n\r\n\r\nmy_function(MyEnum.A)\r\n\r\n```\r\n\r\nCurrently, this will raise the following exception:\r\n```\r\nerror: Argument 1 to \"assert_never\" has incompatible type\r\n\"Literal[MyEnum.B, MyEnum.C]\"; expected \"NoReturn\" [arg-type]\r\n assert_never(a)\r\n```\r\n\r\nwhere the following would not:\r\n\r\n```python\r\ndef my_function(a: MyEnum) -> bool:\r\n if a == MyEnum.A:\r\n return True\r\n elif a == MyEnum.B:\r\n return False\r\n elif a == MyEnum.C:\r\n return False\r\n assert_never(a)\r\n```\r\n\r\n**Pitch**\r\n\r\nIf you wish to do the same thing for multiple enums in that particular function and also want exhaustiveness checking, you need to type each case out individually and then return the same thing, which is not great (DRY etc...).\r\n","author":{"url":"https://github.com/chrisbeardy","@type":"Person","name":"chrisbeardy"},"datePublished":"2023-09-12T09:28:04Z","url":"https://github.com/python/mypy/issues/16093"}
| 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:d6657302-0420-d4d6-c87d-9f94b2ca0cdc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C7A:12476C:1BFB588:24DD23B:6B002A21 |
| html-safe-nonce | fbc5b69c3c03af0be982a718c3fc8a73a1b855d47f7e0951f630ad548ffc01c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzdBOjEyNDc2QzoxQkZCNTg4OjI0REQyM0I6NkIwMDJBMjEiLCJ2aXNpdG9yX2lkIjoiMzQ2MzAxNTkxMzc0MDE1MDA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 41ae43124303fa566cd677916dba37f5efae3ca784135e00770f535fadbfe0b4 |
| hovercard-subject-tag | issue:1892078601 |
| 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/16093/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1dfe3316b057a337529d4adc0cb14f6a26dc2a68213f659084ae6ece5dc274f8/python/mypy/issues/16093 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1dfe3316b057a337529d4adc0cb14f6a26dc2a68213f659084ae6ece5dc274f8/python/mypy/issues/16093 |
| og:image:alt | Feature Allow the use of the in statement when doing exhaustiveness checking. from enum import Enum from typing import assert_never class MyEnum(Enum): A = 1 B = 2 C = 3 def my_function(a: MyEnum) ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chrisbeardy |
| 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