summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-01-23 01:07:14 (GMT)
committerGitHub <noreply@github.com>2024-01-23 01:07:14 (GMT)
commitdcda3aaa6a6c279579da4b96747dc7c3c8216715 (patch)
tree8adfb5b3c21f7f63fc817be5ba5e72a82b537d31 /Doc
parentf5d9980217b2f36d095aa58a9b949b828f113082 (diff)
downloadcpython-dcda3aaa6a6c279579da4b96747dc7c3c8216715.zip
cpython-dcda3aaa6a6c279579da4b96747dc7c3c8216715.tar.gz
cpython-dcda3aaa6a6c279579da4b96747dc7c3c8216715.tar.bz2
[3.11] gh-66944: Note that the `contextlib.closing` example is for illustrative purposes (GH-112198) (#114459)
Diffstat (limited to 'Doc')
-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 c01112a..fd26488 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)