8000 [3.13] gh-135171: Update documentation for the generator expression (GH-135351) by miss-islington · Pull Request #135525 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.13] gh-135171: Update documentation for the generator expression (GH-135351) #135525

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 1 commit into from
Jun 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-135171: Update documentation for the generator expression (GH-135351)
* gh-135171: Update documentation for the generator expression

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

* Update Doc/reference/expressions.rst

Co-authored-by: Brian Skinn <brian.skinn@gmail.com>

---------
(cherry picked from commit 8979d3a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Brian Skinn <brian.skinn@gmail.com>
  • Loading branch information
2 people authored and miss-islington committed Jun 15, 2025
commit 68340d994f2b0421527793f9ab80dc5943098cbd
5 changes: 3 additions & 2 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ 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
produced by it will be emitted at the point where the generator expression
leftmost :keyword:`!for` clause is immediately evaluated, and the
:term:`iterator` is immediately created for that iterable, so that an error
produced while creating the iterator will be emitted at the point where the generator expression
is defined, rather than at the point where the first value is retrieved.
Subsequent :keyword:`!for` clauses and any filter condition in the leftmost
:keyword:`!for` clause cannot be evaluated in the enclosing scope as they may
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Document that the :term:`iterator` for the leftmost :keyword:`!for` clause
in the generator expression is created immediately.
Loading
0