summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2024-01-23 01:00:53 (GMT)
committerGitHub <noreply@github.com>2024-01-23 01:00:53 (GMT)
commit9af9ac153acb4198878ad81ef438aca2b808e45d (patch)
treec4367e73f6c432f33cd5f400f225acc8f02521e5
parent647b6cc7f16c03535cede7e1748a58ab884135b2 (diff)
downloadcpython-9af9ac153acb4198878ad81ef438aca2b808e45d.zip
cpython-9af9ac153acb4198878ad81ef438aca2b808e45d.tar.gz
cpython-9af9ac153acb4198878ad81ef438aca2b808e45d.tar.bz2
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>
-rw-r--r--Doc/library/contextlib.rst8
1 files changed, 8 insertions, 0 deletions
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index aab319c..b73373b 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -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)