mirror of
https://github.com/python/cpython.git
synced 2025-08-19 08:11:46 +00:00
[3.12] gh-66944: Note that the contextlib.closing
example is for illustrative purposes (GH-112198) (#114458)
This commit is contained in:
parent
ed567c1e1f
commit
536b66f8fa
1 changed files with 8 additions and 0 deletions
|
@ -182,6 +182,14 @@ Functions and classes provided:
|
||||||
without needing to explicitly close ``page``. Even if an error occurs,
|
without needing to explicitly close ``page``. Even if an error occurs,
|
||||||
``page.close()`` will be called when the :keyword:`with` block is exited.
|
``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)
|
.. function:: aclosing(thing)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue