Skip to content

gh-135171: Update documentation for the generator expression #135351

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jun 10, 2025

Document that the iterator for the leftmost "for" clause is created immediately.


📚 Documentation preview 📚: https://cpython-previews--135351.org.readthedocs.build/

Document that the iterator for the leftmost "for" clause is created
immediately.
@@ -406,7 +406,8 @@ brackets or curly braces.
Variables used in the generator expression are evaluated lazily when the
:meth:`~generator.__next__` method is called for the generator object (in the same
fashion as normal generators). However, the iterable expression in the
leftmost :keyword:`!for` clause is immediately evaluated, so that an error
leftmost :keyword:`!for` clause is immediately evaluated, and the
Copy link
Member

Choose a reason for hiding this comment

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

What about async for?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is the same. async for is mentioned at the end of this section. What is written here applies to synchronous and asynchronous generator expressions (which are created not only by async for).

Co-authored-by: Brian Skinn <brian.skinn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants