-
-
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
base: main
Are you sure you want to change the base?
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
| 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?
|
Creo que si puesto que esto conviene para el sistema para los que no
tenemos un contrato como tal con para tener mejores oportunidades
El mié, 14 de ene de 2026, 7:46 p.m., Dino Viehland <
***@***.***> escribió:
… ***@***.**** approved this pull request.
Other than the one nit looks good to me
------------------------------
In Python/codegen.c
<#143569 (comment)>:
> @@ -4545,7 +4571,7 @@ codegen_async_comprehension_generator(compiler *c, location loc,
asdl_comprehension_seq *generators,
int gen_index, int depth,
expr_ty elt, expr_ty val, int type,
- int iter_on_stack)
+ IterStackState iter_on_stack)
nit: Is it worth renaming these to something like iter_state like it is
in codegen_comprehension?
—
Reply to this email directly, view it on GitHub
<#143569 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BM2Z756W3CE75JBNXPHA3W34G3WQBAVCNFSM6AAAAACRCMEWPGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTMNRTGA3TGMZYHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
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.