Skip to content

Commit a80d47e

Browse files
miss-islingtonserhiy-storchakabskinn
authored
[3.13] gh-135171: Update documentation for the generator expression (GH-135351) (GH-135525)
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 --------- (cherry picked from commit 8979d3a) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Brian Skinn <brian.skinn@gmail.com>
1 parent 1534077 commit a80d47e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Doc/reference/expressions.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,9 @@ brackets or curly braces.
407407
Variables used in the generator expression are evaluated lazily when the
408408
:meth:`~generator.__next__` method is called for the generator object (in the same
409409
fashion as normal generators). However, the iterable expression in the
410-
leftmost :keyword:`!for` clause is immediately evaluated, so that an error
411-
produced by it will be emitted at the point where the generator expression
410+
leftmost :keyword:`!for` clause is immediately evaluated, and the
411+
:term:`iterator` is immediately created for that iterable, so that an error
412+
produced while creating the iterator will be emitted at the point where the generator expression
412413
is defined, rather than at the point where the first value is retrieved.
413414
Subsequent :keyword:`!for` clauses and any filter condition in the leftmost
414415
:keyword:`!for` clause cannot be evaluated in the enclosing scope as they may
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Document that the :term:`iterator` for the leftmost :keyword:`!for` clause
2+
in the generator expression is created immediately.

0 commit comments

Comments
 (0)