From 2601dae1830bccbb64b44b777b083aac6b72107a Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 18 Mar 2025 10:34:45 +0100 Subject: [PATCH] [3.12] gh-130132: properly free resources in `urrlib.urlopen` examples (GH-130280) (#131395) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gh-130132: properly free resources in `urrlib.urlopen` examples (GH-130280) (cherry picked from commit 77d2fd441320ca365c34e21c475d3878f3d5d833) Co-authored-by: Kanishk Pachauri Co-authored-by: sobolevn Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/urllib.request.rst | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index 0c5aa0458c6e..5d1d8a245907 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -1244,7 +1244,10 @@ It is also possible to achieve the same result without using the >>> import urllib.request >>> f = urllib.request.urlopen('http://www.python.org/') - >>> print(f.read(100).decode('utf-8')) + >>> try: + ... print(f.read(100).decode('utf-8')) + ... finally: + ... f.close()