Skip to content

gh-92261: Disallow iteration of Union (and other _SpecialForms) - #92262

Merged
serhiy-storchaka merged 10 commits into
python:mainfrom
mrahtz:disallow-union-iteration
May 8, 2022
Merged

serhiy-storchaka merged 10 commits into
python:mainfrom
mrahtz:disallow-union-iteration

Conversation

@mrahtz

@mrahtz mrahtz commented May 3, 2022 •

Copy link
Copy Markdown
Contributor

As #92261 describes, list(Union) currently results in a hang because _SpecialForm.__getitem__ is used for iteration, meaning that list(Union) effectively does Union[0], Union[1], ....

This PR fixes it by implementing _SpecialForm.__iter__, which takes priority over _SpecialForm.__getitem__ when iterating.

Edit: and now also explicitly setting __iter__ = None on a number of other things in typing.py, to prevent similar errors with other things.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants