Skip to content

Commit fe86c40

Browse files
committed
Doc: Clarify generator.close() documentation
Replace 'sends' with 'raises' and clarify that close() is equivalent to throw(GeneratorExit). This makes the documentation clearer and avoids confusion with generator.send().
1 parent 66a86e1 commit fe86c40

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Doc/reference/expressions.rst

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

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

628-
Sends a :exc:`GeneratorExit` exception to the generator at the point where
629-
the generator function was paused. If the generator function catches the
630-
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
631632
value, this value is returned from :meth:`close`. If the generator function
632633
is already closed, or raises :exc:`GeneratorExit` (by not catching the
633634
exception), :meth:`close` returns :const:`None`. If the generator yields a

0 commit comments

Comments
 (0)