Skip to content

Commit 23585e4

Browse files
scopAA-Turner
authored andcommitted
pythongh-66944: Note that the contextlib.closing example is for illustrative purposes (python#112198)
Co-authored-by: Adam Turner <[email protected]>
1 parent 2b9828e commit 23585e4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/library/contextlib.rst

Lines changed: 8 additions & 0 deletions
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)