GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-143493: Conform to spec for generator expressions while supporting virtual iterators by markshannon · Pull Request #143569 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Jan 8, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • 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.
  • Issue: Behavior of generator expressions doesn't match the docs when passed a non-iterable #143493

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon
Conform to spec for generator expressions while supporting virtual it…
4deca76
…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.
@markshannon
markshannon requested a review from iritkatriel as a code owner January 8, 2026 14:53
@bedevere-app bedevere-app Bot mentioned this pull request Jan 8, 2026
Behavior of generator expressions doesn't match the docs when passed a non-iterable #143493
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Jan 8, 2026
@markshannon
Add news
0d9ded3
@markshannon
markshannon requested a review from serhiy-storchaka January 8, 2026 15:00
J2085isa

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

J2085isa

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed Jan 9, 2026
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon

markshannon commented Jan 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

BTW, what happens when __iter__() raises StopIteration?

The exception is raised before the generator is created and the traceback shows the iterable as the location of the exception.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented Jan 9, 2026

Copy link
Copy Markdown
Member Author

Is similar change needed for asynchronous generators?

I don't think asynchronous generators were ever changed, so they still have the old behavior from 3.13 and earlier.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DinoV
DinoV approved these changes Jan 15, 2026
View reviewed changes

@DinoV DinoV left a comment

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 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)

@DinoV DinoV Jan 14, 2026

Copy link
Copy Markdown
Contributor

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@markshannon markshannon Jan 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jan 15, 2026
@python python deleted a comment from J2085isa Jan 15, 2026
@markshannon
Rename enum
f374397
@markshannon
markshannon merged commit ae53da5 into python:main Jan 16, 2026
71 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 16, 2026
@bedevere-bot

bedevere-bot commented Jan 16, 2026

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 macOS 3.x (tier-2) has failed when building commit ae53da5.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/725/builds/12565) and take a look at the build logs.
  4. Check if the failure is related to this commit (ae53da5) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/725/builds/12565

Failed tests:

  • test_urllib2net

Failed subtests:

  • test_call_count_thread_safe - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_call_count_thread_safe
  • test_preauth_data_to_tls_server - test.test_ssl.TestPreHandshakeClose.test_preauth_data_to_tls_server

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_ssl.py", line 5476, in test_preauth_data_to_tls_server
    self.assertIn("before TLS handshake with data", wrap_error.args[1])
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'before TLS handshake with data' not found in '[SSL: RECORD_LAYER_FAILURE] record layer failure (_ssl.c:1096)'


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 219, in test_call_count_thread_safe
    self.assertEqual(m.call_count, LOOPS * THREADS)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 998 != 1000
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DinoV DinoV mentioned this pull request Jan 16, 2026
gh-142913: Update generated code that conflicted with other landed change #143932
Merged
meta-codesync Bot pushed a commit to facebookincubator/cinderx that referenced this pull request Jan 21, 2026
@DinoV @meta-codesync
Update for future upstream changes
61b4aeb
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: mpage

Differential Revision: D90706769

fbshipit-source-id: 229a355c62e4b07ca0f3853ba91ac31b81946a8b
meta-codesync Bot pushed a commit to facebookincubator/cinderx that referenced this pull request Jan 22, 2026
@DinoV @meta-codesync
Fix the CinderX 3.15 build
92da407
Summary:
Fixes up the CinderX build after the latest import. This brought in python/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 to python/cpython#143569 where we need to update the interpreter loop.

Also python/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: itamaro

Differential Revision: D91146024

fbshipit-source-id: 6da3ef18fe5fe5f79e29a71cdbe98491bbb45a9d
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
@markshannon @thunder-coding
pythonGH-143493: Conform to spec for generator expressions while supp…
f2185b1
…orting virtual iterators (pythonGH-143569)

* 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.
@iritkatriel iritkatriel mentioned this pull request Aug 25, 2026
gh-143493: fix cleanup on errors in codegen_comprehension #156374
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@DinoV DinoV DinoV approved these changes
@iritkatriel iritkatriel Awaiting requested review from iritkatriel iritkatriel is a code owner
+1 more reviewer
@J2085isa J2085isa J2085isa left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@markshannon @bedevere-bot @DinoV @serhiy-storchaka @J2085isa
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.