Title: Cannot return `Enum` instance in `classmethod` marked as `Self` · Issue #14650 · python/mypy · GitHub
Open Graph Title: Cannot return `Enum` instance in `classmethod` marked as `Self` · Issue #14650 · python/mypy
X Title: Cannot return `Enum` instance in `classmethod` marked as `Self` · Issue #14650 · python/mypy
Description: Bug Report It is not possible to annotate an Enum classmethod returning Self if the method returns a specific Enum variant. To Reproduce from enum import Enum, auto, unique from typing_extensions import Self @unique class Color(Enum): Re...
Open Graph Description: Bug Report It is not possible to annotate an Enum classmethod returning Self if the method returns a specific Enum variant. To Reproduce from enum import Enum, auto, unique from typing_extensions i...
X Description: Bug Report It is not possible to annotate an Enum classmethod returning Self if the method returns a specific Enum variant. To Reproduce from enum import Enum, auto, unique from typing_extensions i...
Opengraph URL: https://github.com/python/mypy/issues/14650
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot return `Enum` instance in `classmethod` marked as `Self`","articleBody":"**Bug Report**\r\n\r\nIt is not possible to annotate an `Enum` `classmethod` returning `Self` if the method returns a specific `Enum` variant.\r\n\r\n**To Reproduce**\r\n\r\n```py\r\nfrom enum import Enum, auto, unique\r\nfrom typing_extensions import Self\r\n\r\n@unique\r\nclass Color(Enum):\r\n Red = auto()\r\n Green = auto()\r\n Blue = auto()\r\n\r\n @classmethod\r\n def stop(cls) -> Self:\r\n return cls.Red\r\n\r\nprint(Color.stop())\r\n```\r\n**Expected Behavior**\r\n\r\nNo type check errors. We are using `Self` to reduce the forward reference problem and avoid `from __future__ import annotations`.\r\n\r\n**Actual Behavior**\r\n\r\n```\r\n$ mypy --strict main.py\r\nmain.py:14: error: Incompatible return value type (got \"Color\", expected \"Self\") [return-value]\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 1.0.0\r\n- Mypy command-line flags: `--strict`\r\n- Mypy configuration options from `mypy.ini` (and other config files): N/A\r\n- Python version used: 3.10.8\r\n- `typing_extensions`: 4.4.0\r\n","author":{"url":"https://github.com/johnthagen","@type":"Person","name":"johnthagen"},"datePublished":"2023-02-08T18:43:17Z","url":"https://github.com/python/mypy/issues/14650"}
| 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:59436700-1197-c190-93d1-66f114ddf6fc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9598:37534:2A2F3:38A68:6B004E39 |
| html-safe-nonce | 1af0b7b87927e6e0fe8e23109785a6a4ab2d6b6c7b30b7227be7e564518ce2cc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTk4OjM3NTM0OjJBMkYzOjM4QTY4OjZCMDA0RTM5IiwidmlzaXRvcl9pZCI6Ijg2NDQ2NzYyOTI3Mzk4Nzg0NTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e58171bffe4aac2514b954cb3d422f7479e4afea10422896a2b40ae23cb6d13f |
| hovercard-subject-tag | issue:1576621044 |
| 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/14650/issue_layout |
| twitter:image | https://opengraph.githubassets.com/499bc79e8ea1764e8a3ccf2511c05f9467ea4790c1a9dd514cfcb2ba51ff8c31/python/mypy/issues/14650 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/499bc79e8ea1764e8a3ccf2511c05f9467ea4790c1a9dd514cfcb2ba51ff8c31/python/mypy/issues/14650 |
| og:image:alt | Bug Report It is not possible to annotate an Enum classmethod returning Self if the method returns a specific Enum variant. To Reproduce from enum import Enum, auto, unique from typing_extensions i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johnthagen |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width