Title: Duplicate fields in Enum must raise an error · Issue #11248 · python/mypy · GitHub
Open Graph Title: Duplicate fields in Enum must raise an error · Issue #11248 · python/mypy
X Title: Duplicate fields in Enum must raise an error · Issue #11248 · python/mypy
Description: I have this example: from enum import Enum class A(Enum): x = 1 x = 2 reveal_type(A.x) Mypy is happy with it: » mypy ex.py ex.py:8: note: Revealed type is "Literal[ex.A.x]?" But, it raises in runtime: » python ex.py Traceback (most recen...
Open Graph Description: I have this example: from enum import Enum class A(Enum): x = 1 x = 2 reveal_type(A.x) Mypy is happy with it: » mypy ex.py ex.py:8: note: Revealed type is "Literal[ex.A.x]?" But, it raises in runti...
X Description: I have this example: from enum import Enum class A(Enum): x = 1 x = 2 reveal_type(A.x) Mypy is happy with it: » mypy ex.py ex.py:8: note: Revealed type is "Literal[ex.A.x]?" But, it raise...
Opengraph URL: https://github.com/python/mypy/issues/11248
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Duplicate fields in Enum must raise an error","articleBody":"I have this example:\r\n\r\n```python\r\nfrom enum import Enum\r\n\r\nclass A(Enum):\r\n x = 1\r\n x = 2\r\n\r\nreveal_type(A.x)\r\n```\r\n\r\nMypy is happy with it:\r\n\r\n```python\r\n» mypy ex.py\r\nex.py:8: note: Revealed type is \"Literal[ex.A.x]?\"\r\n```\r\n\r\nBut, it raises in runtime:\r\n\r\n```python\r\n» python ex.py\r\nTraceback (most recent call last):\r\n File \"/Users/sobolev/Desktop/mypy/ex.py\", line 4, in \u003cmodule>\r\n class A(Enum):\r\n File \"/Users/sobolev/Desktop/mypy/ex.py\", line 6, in A\r\n x = 2\r\n File \"/Users/sobolev/.pyenv/versions/3.9.1/lib/python3.9/enum.py\", line 99, in __setitem__\r\n raise TypeError('Attempted to reuse key: %r' % key)\r\nTypeError: Attempted to reuse key: 'x'\r\n```\r\n\r\nThis is a part of my \"better enum\" series:\r\n- https://github.com/python/mypy/pull/11247\r\n- https://github.com/python/mypy/pull/10852\r\n- https://github.com/python/mypy/issues/10858","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2021-10-02T14:54:32Z","url":"https://github.com/python/mypy/issues/11248"}
| 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:53630690-9ee5-0bf1-7da1-ce2f6a10fc02 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D468:102136:4DB522:67D03A:6B002F2D |
| html-safe-nonce | e1cc77c57d62a11c63ce55719eb7e9994a303600df8e346e20b40dbb43d9db50 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDY4OjEwMjEzNjo0REI1MjI6NjdEMDNBOjZCMDAyRjJEIiwidmlzaXRvcl9pZCI6IjI4ODc1NjUxOTI3MzkxNzIxNDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | faf55d7dbe2a4036e76800aa1cf1782783543dc3bfa5f58d99f42a9dceb66a8b |
| hovercard-subject-tag | issue:1014074066 |
| 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/11248/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ca024de001edc293ba165b72d5f9defb3af20aad8a00dba70e6b9671607077c2/python/mypy/issues/11248 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ca024de001edc293ba165b72d5f9defb3af20aad8a00dba70e6b9671607077c2/python/mypy/issues/11248 |
| og:image:alt | I have this example: from enum import Enum class A(Enum): x = 1 x = 2 reveal_type(A.x) Mypy is happy with it: » mypy ex.py ex.py:8: note: Revealed type is "Literal[ex.A.x]?" But, it raises in runti... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sobolevn |
| 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