Skip to content

Commit 536b66f

Browse files
[3.12] gh-66944: Note that the contextlib.closing example is for illustrative purposes (GH-112198) (#114458)
1 parent ed567c1 commit 536b66f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/library/contextlib.rst

+8
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ Functions and classes provided:
182182
without needing to explicitly close ``page``. Even if an error occurs,
183183
``page.close()`` will be called when the :keyword:`with` block is exited.
184184

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

186194
.. function:: aclosing(thing)
187195

0 commit comments

Comments
 (0)