-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
GH-143493: Conform to spec for generator expressions while supporting virtual iterators #143569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-143493: Conform to spec for generator expressions while supporting virtual iterators #143569
Conversation
…erators * Moves the `GET_ITER` instruction into the generator function preamble. This means the the iterable is converted into an iterator during generator creation, as documented, but keeps it in the same code object allowing optimization.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the code was changed so much since I worked with it, that I can no longer make qualified review. I can understand particular changes, but I cannot catch if something was missed. The original idea looks reasonably.
BTW, what happens when __iter__() raises StopIteration?
Is similar change needed for asynchronous generators?
The exception is raised before the generator is created and the traceback shows the iterable as the location of the exception. |
I don't think asynchronous generators were ever changed, so they still have the old behavior from 3.13 and earlier. |
DinoV
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the one nit looks good to me
Python/codegen.c
Outdated
| int gen_index, int depth, | ||
| expr_ty elt, expr_ty val, int type, | ||
| int iter_on_stack) | ||
| IterStackState iter_on_stack) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Is it worth renaming these to something like iter_state like it is in codegen_comprehension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't it state, it is its location. Maybe I'll rename IterStackState instead.
|
GET_ITERinstruction into the generator function preamble. This means the the iterable is converted into an iterator during generator creation, as documented, but keeps it in the same code object allowing optimization.