Uh oh!
There was an error while loading. Please reload this page.
gh-92261: Disallow iteration of Union (and other _SpecialForms) - #92262
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
What about list(list)?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
mrahtz
commented
May 7, 2022
[Serhiy]
I've added a couple of tests to |
serhiy-storchaka
commented
May 7, 2022
For me, the style is too verbose, but the code does everything right, and I don't want to be too picky. |
Uh oh!
There was an error while loading. Please reload this page.
JelleZijlstra
commented
May 9, 2022
Should we apply this to 3.11 too? |
gvanrossum
left a comment
There was a problem hiding this comment.
For a pure bugfix it seems rather involved. And since it is only intending to report a better error for something that's clearly invalid, I am not inclined to backport it. (Even though it has so many pieces that it will likely cause a fair amount of merge issues for future, simpler, bugfixes that do deserve being backported.
JelleZijlstra
commented
May 9, 2022
It's not just an error message though: on 3.11 |
gvanrossum
commented
May 9, 2022
Okay, then I'll leave it to your judgment (and that of @pablogsal). Be sure to also backport the one-line fix for slots. :-) |
miss-islington
commented
May 9, 2022
Thanks @mrahtz for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
…pythonGH-92262) (cherry picked from commit 4739997) Co-authored-by: Matthew Rahtz <matthew.rahtz@gmail.com>
bedevere-bot
commented
May 9, 2022
GH-92582 is a backport of this pull request to the 3.11 branch. |
As #92261 describes,
list(Union)currently results in a hang because_SpecialForm.__getitem__is used for iteration, meaning thatlist(Union)effectively doesUnion[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__ = Noneon a number of other things intyping.py, to prevent similar errors with other things.