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>
This commit is contained in:
Ville Skyttä 2024-01-23 03:00:53 +02:00 committed by GitHub
parent 647b6cc7f1
commit 9af9ac153a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)