-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
base: main
Are you sure you want to change the base?
gh-135171: Update documentation for the generator expression #135351
Conversation
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 |
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.
What about async for?
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 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>
Document that the iterator for the leftmost "for" clause is created immediately.
📚 Documentation preview 📚: https://cpython-previews--135351.org.readthedocs.build/