]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-66944: Note that the `contextlib.closing` example is for illustrative purpo...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 23 Jan 2024 01:07:34 +0000 (02:07 +0100)
committerGitHub <noreply@github.com>
Tue, 23 Jan 2024 01:07:34 +0000 (01:07 +0000)
Doc/library/contextlib.rst

index aab319cbe7405ec98dfdb2b797b018d11396379e..b73373bc2363fb02c0050680743ee309c3bada4a 100644 (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)