Skip to content

Commit

Permalink
pythongh-66944: Note that the contextlib.closing example is for ill…
Browse files Browse the repository at this point in the history
…ustrative purposes (pythonGH-112198)

(cherry picked from commit 9af9ac1)

Co-authored-by: Ville Skyttä <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
  • Loading branch information
2 people authored and miss-islington committed Jan 23, 2024
1 parent ed567c1 commit 9b1a9ff
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Doc/library/contextlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ Functions and classes provided:
without needing to explicitly close ``page``. Even if an error occurs,
``page.close()`` will be called when the :keyword:`with` block is exited.

.. note::

Most types managing resources support the :term:`context manager` protocol,
which closes *thing* on leaving the :keyword:`with` statment.
As such, :func:`!closing` is most useful for third party types that don't
support context managers.
This example is purely for illustration purposes,
as :func:`~urllib.request.urlopen` would normally be used in a context manager.

.. function:: aclosing(thing)

Expand Down

0 comments on commit 9b1a9ff

Please sign in to comment.