Skip to content

Docs: Clarify generator.close() behavior regarding GeneratorExit #135819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,12 @@ methods.
More information about generators can be found in :ref:`the documentation for
the yield expression <yieldexpr>`.

.. note::

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

.. _typesseq:

Expand Down
Loading