Title: Trying to iterate over typing.Union results in hang · Issue #92261 · python/cpython · GitHub
Open Graph Title: Trying to iterate over typing.Union results in hang · Issue #92261 · python/cpython
X Title: Trying to iterate over typing.Union results in hang · Issue #92261 · python/cpython
Description: If you accidentally iterate over a Union, you get a hang: from typing import Union list(Union) # ...hang It looks like it's an infinite loop: from typing import Union for i in Union: print(i) # 0, 1, 2, ... As far as I can tell, this hap...
Open Graph Description: If you accidentally iterate over a Union, you get a hang: from typing import Union list(Union) # ...hang It looks like it's an infinite loop: from typing import Union for i in Union: print(i) # 0, ...
X Description: If you accidentally iterate over a Union, you get a hang: from typing import Union list(Union) # ...hang It looks like it's an infinite loop: from typing import Union for i in Union: print(i) #...
Opengraph URL: https://github.com/python/cpython/issues/92261
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Trying to iterate over typing.Union results in hang","articleBody":"If you accidentally iterate over a `Union`, you get a hang:\r\n\r\n```python\r\nfrom typing import Union\r\nlist(Union)\r\n# ...hang\r\n```\r\n\r\nIt looks like it's an infinite loop:\r\n\r\n```python\r\nfrom typing import Union\r\nfor i in Union:\r\n print(i)\r\n# 0, 1, 2, ...\r\n```\r\n\r\nAs far as I can tell, this happens because `typing.Union` is implemented using `typing._SpecialForm`, and `_SpecialForm` is implemented using `__getitem__` to support parameterisation like `Union[int]`. Unfortunately, because `_SpecialForm` doesn't implement `__iter__`, `__getitem__` is also used for iteration - meaning that when trying to iterate, we effectively do `Union[0]`, `Union[1]`, etc.","author":{"url":"https://github.com/mrahtz","@type":"Person","name":"mrahtz"},"datePublished":"2022-05-03T20:09:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/92261/cpython/issues/92261"}
| 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:8a4a2055-394f-0f30-3e0d-df645e7cf599 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8E8:64491:D85DE1:12B9E82:696A830F |
| html-safe-nonce | 89fadda92314e5d38155537c9f7d50f111253a2b72e66b80cd1cb882da7ef7b4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEU4OjY0NDkxOkQ4NURFMToxMkI5RTgyOjY5NkE4MzBGIiwidmlzaXRvcl9pZCI6Ijk0OTcwMDk0NTQ2NzA0ODcxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1f080fd6803a80dbb8398d072c6a46e4a509c04b3636e8f276783824ca976409 |
| hovercard-subject-tag | issue:1224576296 |
| 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/92261/issue_layout |
| twitter:image | https://opengraph.githubassets.com/60a5eeb03956d84a05c6f5df6cba371475ef24126fd8d2a5e1d06b70b67f2396/python/cpython/issues/92261 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/60a5eeb03956d84a05c6f5df6cba371475ef24126fd8d2a5e1d06b70b67f2396/python/cpython/issues/92261 |
| og:image:alt | If you accidentally iterate over a Union, you get a hang: from typing import Union list(Union) # ...hang It looks like it's an infinite loop: from typing import Union for i in Union: print(i) # 0, ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mrahtz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 913560fa317c3c5a71e34f9b19253c9f09d02b4b958a86c2a56f4c8541116377 |
| 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 | 5998c30593994bf2589055aef7b22d368a499367 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width