]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-135171: Update documentation for the generator expression (GH-135351)
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 15 Jun 2025 00:32:44 +0000 (03:32 +0300)
committerGitHub <noreply@github.com>
Sun, 15 Jun 2025 00:32:44 +0000 (17:32 -0700)
* 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>
---------

Co-authored-by: Brian Skinn <brian.skinn@gmail.com>
Doc/reference/expressions.rst
Misc/NEWS.d/next/Documentation/2025-06-10-17-02-06.gh-issue-135171.quHvts.rst [new file with mode: 0644]

index 2a550b504ca7652c0ace08a53569e9bc4615cb60..3d3bf1d9840eefaf15137d4108777461890a9a06 100644 (file)
@@ -406,8 +406,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
diff --git a/Misc/NEWS.d/next/Documentation/2025-06-10-17-02-06.gh-issue-135171.quHvts.rst b/Misc/NEWS.d/next/Documentation/2025-06-10-17-02-06.gh-issue-135171.quHvts.rst
new file mode 100644 (file)
index 0000000..129ff74
--- /dev/null
@@ -0,0 +1,2 @@
+Document that the :term:`iterator` for the leftmost :keyword:`!for` clause
+in the generator expression is created immediately.