Skip to content

GH-127682: Only call __iter__ once in generator expressions. #132351

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

Merged
merged 6 commits into from
Apr 11, 2025

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Apr 10, 2025

Removes the extra GET_ITER instruction emitted when creating a generator expression.

This:

  • Allows iterables producing iterators than do not have an __iter__ method to be used in generator expressions, as they were up until 3.12.
  • Makes generator expressions behave the same as all other generators in this regard.

@markshannon markshannon merged commit d87e7f3 into python:main Apr 11, 2025
42 checks passed
@miss-islington-app
Copy link

Thanks @markshannon for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@markshannon markshannon deleted the fix-127682 branch April 11, 2025 08:37
@miss-islington-app
Copy link

Sorry, @markshannon, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker d87e7f35297d34755026173d84a38eedfbed78de 3.13

@Fidget-Spinner
Copy link
Member

Do you need to bump the magic number here? I forgot if compiler-only changes need that.

@brandtbucher
Copy link
Member

I don’t think so, since the bytecode format and behavior is unchanged.

markshannon added a commit that referenced this pull request Apr 29, 2025
Only call `__iter__` once in generator expressions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs backport to 3.13 bugs and security fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants