Title: Enum exhaustiveness checks fail with `@enum.member`-decorated members · Issue #18722 · python/mypy · GitHub
Open Graph Title: Enum exhaustiveness checks fail with `@enum.member`-decorated members · Issue #18722 · python/mypy
X Title: Enum exhaustiveness checks fail with `@enum.member`-decorated members · Issue #18722 · python/mypy
Description: Bug Report Functions decorated with @enum.member are as rightful enum members as simple non-callable attributes. Beware of #18721. To Reproduce from enum import Enum, member from typing import assert_never class E1(Enum): C = 1 def check...
Open Graph Description: Bug Report Functions decorated with @enum.member are as rightful enum members as simple non-callable attributes. Beware of #18721. To Reproduce from enum import Enum, member from typing import asse...
X Description: Bug Report Functions decorated with @enum.member are as rightful enum members as simple non-callable attributes. Beware of #18721. To Reproduce from enum import Enum, member from typing import asse...
Opengraph URL: https://github.com/python/mypy/issues/18722
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enum exhaustiveness checks fail with `@enum.member`-decorated members","articleBody":"**Bug Report**\n\nFunctions decorated with `@enum.member` are as rightful enum members as simple non-callable attributes.\n\nBeware of #18721.\n\n**To Reproduce**\n\n```python\nfrom enum import Enum, member\nfrom typing import assert_never\n\nclass E1(Enum):\n C = 1\n\ndef check_1(e: E1) -> None:\n match e:\n case E1.C:\n pass\n case other:\n assert_never(other) # OK\n\n if e is E1.C:\n pass\n else:\n assert_never(e) # OK\n\n\nclass E2(Enum):\n @member\n def C() -> None: ... # E: Method must have at least one argument. Did you forget the \"self\" argument? [misc]\n\ndef check_2(e: E2) -> None:\n match e:\n case E2.C:\n pass\n case other:\n assert_never(other) # E: Argument 1 to \"assert_never\" has incompatible type \"E2\"; expected \"Never\" [arg-type]\n\n if e is E2.C:\n pass\n else:\n assert_never(e) # E: Argument 1 to \"assert_never\" has incompatible type \"\u003csubclass of \"enum.member[Callable[[], None]]\" and \"__main__.E2\">\"; expected \"Never\" [arg-type]\n```\n\n[playground](https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=8089cedd77c30d75944c7b478c830ad8)\n\n**Expected Behavior**\n\nGreen output.\n\n**Actual Behavior**\n\n```\nmain.py:22: error: Method must have at least one argument. Did you forget the \"self\" argument? [misc]\nmain.py:29: error: Argument 1 to \"assert_never\" has incompatible type \"E2\"; expected \"Never\" [arg-type]\nmain.py:34: error: Argument 1 to \"assert_never\" has incompatible type \"\u003csubclass of \"member\" and \"E2\">\"; expected \"Never\" [arg-type]\nFound 3 errors in 1 file (checked 1 source file)\n```\n\n**Your Environment**\n\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\n\n- Mypy version used: 1.15.0 and current master\n- Mypy command-line flags: --strict and without\n- Mypy configuration options from `mypy.ini` (and other config files): N/A\n- Python version used: 3.12\n","author":{"url":"https://github.com/sterliakov","@type":"Person","name":"sterliakov"},"datePublished":"2025-02-22T04:15:09Z","url":"https://github.com/python/mypy/issues/18722"}
| 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:0c0f470c-06a4-a45d-6db7-d85ede88d616 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9004:2148FB:234E23D:3004BC8:6B002CC3 |
| html-safe-nonce | 0a5caccab2bf72f9c39fca745fbf05716e47f66f3dbf97e18768c7ae89e4dee5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDA0OjIxNDhGQjoyMzRFMjNEOjMwMDRCQzg6NkIwMDJDQzMiLCJ2aXNpdG9yX2lkIjoiNjg0MTQ3MDU3NDU3Nzg1NTY4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c4f371558ad7aeda403efc5d9403c916bd219aa9b7d6714673d5aaa63f14b8c7 |
| hovercard-subject-tag | issue:2870474844 |
| 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/18722/issue_layout |
| twitter:image | https://opengraph.githubassets.com/73bc942ea45dcfee0148f0867fbab9f43a4533bbc4df098d7815d8a015c600fb/python/mypy/issues/18722 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/73bc942ea45dcfee0148f0867fbab9f43a4533bbc4df098d7815d8a015c600fb/python/mypy/issues/18722 |
| og:image:alt | Bug Report Functions decorated with @enum.member are as rightful enum members as simple non-callable attributes. Beware of #18721. To Reproduce from enum import Enum, member from typing import asse... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sterliakov |
| 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