Skip to content

Commit 92c4aa7

Browse files
Docs: Clarify generator.close() behavior regarding GeneratorExit
1 parent ac9d37c commit 92c4aa7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,12 @@ methods.
956956
More information about generators can be found in :ref:`the documentation for
957957
the yield expression <yieldexpr>`.
958958

959+
.. note::
960+
961+
Calling ``close()`` on a generator raises a ``GeneratorExit`` exception inside the generator
962+
at the point where it is paused. If this exception is not caught or handled inside the
963+
generator (for example, using ``try``/``except`` or ``finally``), then the call to
964+
``close()`` will simply return ``None`` without raising any error to the caller.
959965

960966
.. _typesseq:
961967

0 commit comments

Comments
 (0)