From: Ville Skyttä Date: Tue, 23 Jan 2024 01:00:53 +0000 (+0200) Subject: gh-66944: Note that the `contextlib.closing` example is for illustrative purposes... X-Git-Tag: v3.13.0a4~370 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9af9ac153acb4198878ad81ef438aca2b808e45d;p=thirdparty%2FPython%2Fcpython.git gh-66944: Note that the `contextlib.closing` example is for illustrative purposes (#112198) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index aab319cbe740..b73373bc2363 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -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)