FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-127682: Only call `__iter__` once in generator expressions. by markshannon · Pull Request #132351 · python/cpython · GitHub

Repository navigation

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

Merged
markshannon merged 6 commits into
python:mainfrom
faster-cpython:fix-127682
Apr 11, 2025
Merged

markshannon merged 6 commits into
python:mainfrom
faster-cpython:fix-127682

Conversation

markshannon commented Apr 10, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

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 merged commit d87e7f3 into python:main Apr 11, 2025

Copy link
Copy Markdown

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

markshannon deleted the fix-127682 branch April 11, 2025 08:37

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

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

Comment thread Lib/test/test_genexps.py
>>> list(g)
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

Verify that the outermost for-expression makes an immediate check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is a regression.

Yhg1s commented Jun 5, 2025

Copy link
Copy Markdown
Member

If this change of behaviour is actually desirable (which may require some further discussion to establish), it should be mentioned in the What's New documentation.

Copy link
Copy Markdown
Member Author

See #135171 (comment) for a more detailed analysis

I'll make a PR for the what's new

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL