10000 [3.14] gh-135110: Fix misleading `generator.close()` documentation (G… · python/cpython@ad6c90f · GitHub
[go: up one dir, main page]

Skip to content

Commit ad6c90f

Browse files
[3.14] gh-135110: Fix misleading generator.close() documentation (GH-135152) (GH-135985)
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 0d76dcc) Co-authored-by: Connor Denihan <188690869+cdenihan@users.noreply.github.com>
1 parent 19740b7 commit ad6c90f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Doc/howto/functional.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ generators:
602602
raise an exception inside the generator; the exception is raised by the
603603
``yield`` expression where the generator's execution is paused.
604604

605-
* :meth:`~generator.close` raises a :exc:`GeneratorExit` exception inside the
605+
* :meth:`~generator.close` sends a :exc:`GeneratorExit` exception to the
606606
generator to terminate the iteration. On receiving this exception, the
607607
generator's code must either raise :exc:`GeneratorExit` or
608608
:exc:`StopIteration`; catching the exception and doing anything else is

Doc/reference/expressions.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,10 @@ is already executing raises a :exc:`ValueError` exception.
625625

626626
.. method:: generator.close()
627627

628-
Raises a :exc:`GeneratorExit` at the point where the generator function was
629-
paused. If the generator function catches the exception and returns a
628+
Raises a :exc:`GeneratorExit` exception at the point where the generator
629+
function was paused (equivalent to calling ``throw(GeneratorExit)``).
630+
The exception is raised by the yield expression where the generator was paused.
631+
If the generator function catches the exception and returns a
630632
value, this value is returned from :meth:`close`. If the generator function
631633
is already closed, or raises :exc:`GeneratorExit` (by not catching the
632634
exception), :meth:`close` returns :const:`None`. If the generator yields a

0 commit comments

Comments
 (0)
0