Skip to content

Commit ee141f0

Browse files
miss-islingtonserhiy-storchakabskinn
authored
[3.14] gh-135171: Update documentation for the generator expression (GH-135351) (#135524)
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 <[email protected]> Co-authored-by: Brian Skinn <[email protected]>
1 parent c5f066d commit ee141f0

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
@@ -406,8 +406,9 @@ brackets or curly braces.
406406
Variables used in the generator expression are evaluated lazily when the
407407
:meth:`~generator.__next__` method is called for the generator object (in the same
408408
fashion as normal generators). However, the iterable expression in the
409-
leftmost :keyword:`!for` clause is immediately evaluated, so that an error
410-
produced by it will be emitted at the point where the generator expression
409+
leftmost :keyword:`!for` clause is immediately evaluated, and the
410+
:term:`iterator` is immediately created for that iterable, so that an error
411+
produced while creating the iterator will be emitted at the point where the generator expression
411412
is defined, rather than at the point where the first value is retrieved.
412413
Subsequent :keyword:`!for` clauses and any filter condition in the leftmost
413414
: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)