Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
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 ourterms of service andprivacy 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
Uh oh!
There was an error while loading.Please reload this page.
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.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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?
markshannon commentedJan 9, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The exception is raised before the generator is created and the traceback shows the iterable as the location of the exception. |
markshannon commentedJan 9, 2026
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 likeiter_state like it is incodegen_comprehension?
markshannonJan 15, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 renameIterStackState instead.
ae53da5 intopython:mainUh oh!
There was an error while loading.Please reload this page.
bedevere-bot commentedJan 16, 2026
|
Summary:python/cpython#143569 has fixed a bug introduced in the code gen where passing a non-iterable to a generator doesn't raise immediately. This matches the code gen.Reviewed By: mpageDifferential Revision: D90706769fbshipit-source-id: 229a355c62e4b07ca0f3853ba91ac31b81946a8b
Summary:Fixes up the CinderX build after the latest import. This brought inpython/cpython#142911 which move somethings into ceval.h so that we can directly include it rather than borrowing those functions. We bring back `cinderx-only-headers` and now use them on 3.10 and 3.15+.There's also a fix related topython/cpython#143569 where we need to update the interpreter loop.Alsopython/cpython@bb25f72 seems to have refactored `_PyDict_LookupIndex` to use `_PyDict_LookupIndexAndValue`.There's some more work after this to further reduce our usage of `ceval_macros.h` but this just gets things working again.Reviewed By: itamaroDifferential Revision: D91146024fbshipit-source-id: 6da3ef18fe5fe5f79e29a71cdbe98491bbb45a9d
Uh oh!
There was an error while loading.Please reload this page.
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.