]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-126664: Use `else` instead of `finally` in "The with statement" documentati...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 11 Nov 2024 06:57:15 +0000 (07:57 +0100)
committerGitHub <noreply@github.com>
Mon, 11 Nov 2024 06:57:15 +0000 (06:57 +0000)
gh-126664: Use `else` instead of `finally` in "The with statement" documentation. (GH-126665)
(cherry picked from commit 25257d61cfccc3b4189f96390a5c4db73fd5302c)

Co-authored-by: vivodi <103735539+vivodi@users.noreply.github.com>
Doc/reference/compound_stmts.rst

index 81399901c9cf4605afaf6c5a518a80c0ca0ca900..ddb1337f949e709387937a96cd878410ab99f300 100644 (file)
@@ -534,18 +534,15 @@ is semantically equivalent to::
     enter = type(manager).__enter__
     exit = type(manager).__exit__
     value = enter(manager)
-    hit_except = False
 
     try:
         TARGET = value
         SUITE
     except:
-        hit_except = True
         if not exit(manager, *sys.exc_info()):
             raise
-    finally:
-        if not hit_except:
-            exit(manager, None, None, None)
+    else:
+        exit(manager, None, None, None)
 
 With more than one item, the context managers are processed as if multiple
 :keyword:`with` statements were nested::