Title: Incorrect deduplication of Enum values in `Union[Literal[1], Literal[SomeEnum.one]]` · Issue #103592 · python/cpython · GitHub
Open Graph Title: Incorrect deduplication of Enum values in `Union[Literal[1], Literal[SomeEnum.one]]` · Issue #103592 · python/cpython
X Title: Incorrect deduplication of Enum values in `Union[Literal[1], Literal[SomeEnum.one]]` · Issue #103592 · python/cpython
Description: This was fixed on 3.9 (by #23294 or followups). Here's a test / example: from enum import Enum from typing import Literal, Union, get_args class MyEnum(int, Enum): foo = 1 tp = Union[Literal[MyEnum.foo], Literal[1]] assert len(get_args(t...
Open Graph Description: This was fixed on 3.9 (by #23294 or followups). Here's a test / example: from enum import Enum from typing import Literal, Union, get_args class MyEnum(int, Enum): foo = 1 tp = Union[Literal[MyEnum...
X Description: This was fixed on 3.9 (by #23294 or followups). Here's a test / example: from enum import Enum from typing import Literal, Union, get_args class MyEnum(int, Enum): foo = 1 tp = Union[Literal[My...
Opengraph URL: https://github.com/python/cpython/issues/103592
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect deduplication of Enum values in `Union[Literal[1], Literal[SomeEnum.one]]`","articleBody":"This was fixed on 3.9 (by https://github.com/python/cpython/pull/23294 or followups). Here's a test / example:\r\n\r\n```python\r\nfrom enum import Enum\r\nfrom typing import Literal, Union, get_args\r\n\r\n\r\nclass MyEnum(int, Enum):\r\n foo = 1\r\n\r\ntp = Union[Literal[MyEnum.foo], Literal[1]]\r\nassert len(get_args(tp)) == 2, get_args(tp)\r\n\r\ntp = Union[Literal[1], Literal[MyEnum.foo]]\r\nassert len(get_args(tp)) == 2, get_args(tp)\r\n```\r\n\r\nThese assertions fail on 3.8 since `Union` deduplicates both `Literal`s into the same thing. The reason you need `Literal` here is because enum values are values not types so they can only appear in a Union if they're also within a Literal.\r\n\r\nAs per https://github.com/python/cpython/pull/23294#issuecomment-728659310 maybe the answer here is to not do anything. And in fact I looked into back porting and it was too big of a change to be called a back port. But I didn't see *this specific* issue w/ Enum and Union reported, so I at least wanted to report it and confirm that it is a bug.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103706\n* gh-103720\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/adriangb","@type":"Person","name":"adriangb"},"datePublished":"2023-04-17T16:28:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/103592/cpython/issues/103592"}
| 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:6e283b72-e19c-c646-c9e2-c0aa65e52003 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D144:8ADEB:BF6E92:106E1A7:6969EDFC |
| html-safe-nonce | 79d30a82bd0f765fd73a82d727f845277b9f89c1dd99e624f76bf3022d16a0a3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTQ0OjhBREVCOkJGNkU5MjoxMDZFMUE3OjY5NjlFREZDIiwidmlzaXRvcl9pZCI6IjU0Nzg3MDE3NTY3NTAzNjAwNjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c15c2ba028c634d359ac8810e354aa2f792d6b4276063e258a9763b31a60146b |
| hovercard-subject-tag | issue:1671559504 |
| 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/cpython/103592/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e5f7b5323afd28d9b1a6ad365d6d3b59ed483a03512a98c4eeb1940c26c3e79b/python/cpython/issues/103592 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e5f7b5323afd28d9b1a6ad365d6d3b59ed483a03512a98c4eeb1940c26c3e79b/python/cpython/issues/103592 |
| og:image:alt | This was fixed on 3.9 (by #23294 or followups). Here's a test / example: from enum import Enum from typing import Literal, Union, get_args class MyEnum(int, Enum): foo = 1 tp = Union[Literal[MyEnum... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | adriangb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width