Title: Merge `typing.Union` and `types.UnionType` · Issue #105499 · python/cpython · GitHub
Open Graph Title: Merge `typing.Union` and `types.UnionType` · Issue #105499 · python/cpython
X Title: Merge `typing.Union` and `types.UnionType` · Issue #105499 · python/cpython
Description: Currently, unions created through typing.Union[A, B] and through the PEP-604 syntax A | B are at runtime instances of completely different types, and they differ in exactly what elements they accept. This is confusing and makes it harder...
Open Graph Description: Currently, unions created through typing.Union[A, B] and through the PEP-604 syntax A | B are at runtime instances of completely different types, and they differ in exactly what elements they accep...
X Description: Currently, unions created through typing.Union[A, B] and through the PEP-604 syntax A | B are at runtime instances of completely different types, and they differ in exactly what elements they accep...
Opengraph URL: https://github.com/python/cpython/issues/105499
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Merge `typing.Union` and `types.UnionType`","articleBody":"Currently, unions created through `typing.Union[A, B]` and through the PEP-604 syntax `A | B` are at runtime instances of completely different types, and they differ in exactly what elements they accept. This is confusing and makes it harder for users to detect unions at runtime.\r\n\r\nI propose to proceed in two steps:\r\n\r\n1. Make `typing.Union` an alias for `types.UnionType` and make it so `types.UnionType[A, B]` works, accepting the same types `Union` accepts now.\r\n2. Loosen the rules for what the `|` operator accepts to accept more types that are commonly used in unions.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-105511\n* gh-132061\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2023-06-08T14:07:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/105499/cpython/issues/105499"}
| 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:9a2b96e5-888b-90e7-ac51-8dc946bbbf1a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF34:1E4FEF:F24E4E:13859D5:696B0A3B |
| html-safe-nonce | 9d4ef12d0034d5bac014626f7ed6e3e5e12b526ad7a93f92f8f287a6fb369eda |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjM0OjFFNEZFRjpGMjRFNEU6MTM4NTlENTo2OTZCMEEzQiIsInZpc2l0b3JfaWQiOiIzMjA1MjYzMDAwMTc5NzcxOTYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cb9c1af6a8df45dd2c1570f2f4232be1871b8e0de4bd4995416bbb25f7d7343c |
| hovercard-subject-tag | issue:1747969149 |
| 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/105499/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6fbfb47ecad4767a4cabfb60757196020016e1960265ee89f80f8d9a5eed1999/python/cpython/issues/105499 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6fbfb47ecad4767a4cabfb60757196020016e1960265ee89f80f8d9a5eed1999/python/cpython/issues/105499 |
| og:image:alt | Currently, unions created through typing.Union[A, B] and through the PEP-604 syntax A | B are at runtime instances of completely different types, and they differ in exactly what elements they accep... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width