From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 18 Mar 2025 09:34:45 +0000 (+0100) Subject: [3.12] gh-130132: properly free resources in `urrlib.urlopen` examples (GH-130280... X-Git-Tag: v3.12.10~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2601dae1830bccbb64b44b777b083aac6b72107a;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-130132: properly free resources in `urrlib.urlopen` examples (GH-130280) (#131395) 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> --- 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()