Skip to content

Commit 9af9ac1

Browse files
scopAA-Turner
andauthored
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>
1 parent 647b6cc commit 9af9ac1

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)