https://github.com/python/cpython/commit/a7246323a28a707e8dab9437b1c07ffbc0d5d5a0
commit: a7246323a28a707e8dab9437b1c07ffbc0d5d5a0
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: ZeroIntensity <zintensity...@gmail.com>
date: 2025-06-26T13:34:11Z
summary:

[3.13] gh-135110: Fix misleading `generator.close()` documentation (GH-135152) 
(GH-135986)

gh-135110: Fix misleading `generator.close()` documentation (GH-135152)

The documentation incorrectly stated that generator.close() 'raises' a
GeneratorExit exception. This was misleading because the method doesn't
raise the exception to the caller - it sends the exception internally
to the generator and returns None.
(cherry picked from commit 0d76dccc3b4376ba075a1737f58809e3d83aaaa3)

Co-authored-by: Connor Denihan <188690869+cdeni...@users.noreply.github.com>

files:
M Doc/howto/functional.rst
M Doc/reference/expressions.rst

diff --git a/Doc/howto/functional.rst b/Doc/howto/functional.rst
index 1f0608fb0fc53f..aff651ffc2b91a 100644
--- a/Doc/howto/functional.rst
+++ b/Doc/howto/functional.rst
@@ -602,7 +602,7 @@ generators:
   raise an exception inside the generator; the exception is raised by the
   ``yield`` expression where the generator's execution is paused.
 
-* :meth:`~generator.close` raises a :exc:`GeneratorExit` exception inside the
+* :meth:`~generator.close` sends a :exc:`GeneratorExit` exception to the
   generator to terminate the iteration.  On receiving this exception, the
   generator's code must either raise :exc:`GeneratorExit` or
   :exc:`StopIteration`; catching the exception and doing anything else is
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index 55bae3df25e495..d88134b0edbcad 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -627,8 +627,10 @@ is already executing raises a :exc:`ValueError` exception.
 
 .. method:: generator.close()
 
-   Raises a :exc:`GeneratorExit` at the point where the generator function was
-   paused.  If the generator function catches the exception and returns a
+   Raises a :exc:`GeneratorExit` exception at the point where the generator
+   function was paused (equivalent to calling ``throw(GeneratorExit)``).
+   The exception is raised by the yield expression where the generator was 
paused.
+   If the generator function catches the exception and returns a
    value, this value is returned from :meth:`close`.  If the generator function
    is already closed, or raises :exc:`GeneratorExit` (by not catching the
    exception), :meth:`close` returns :const:`None`.  If the generator yields a

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to