From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 18 Mar 2025 09:33:19 +0000 (+0100) Subject: [3.13] gh-130132: properly free resources in `urrlib.urlopen` examples (GH-130280... X-Git-Tag: v3.13.3~112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f297dabbe05fb240f5eaf0831420a8408ddec5e4;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-130132: properly free resources in `urrlib.urlopen` examples (GH-130280) (#131394) 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 46e0f6275aee..32127e338058 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -1233,7 +1233,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()