]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126664: Use `else` instead of `finally` in "The with statement" documentation...
authorvivodi <103735539+vivodi@users.noreply.github.com>
Mon, 11 Nov 2024 06:47:56 +0000 (14:47 +0800)
committerGitHub <noreply@github.com>
Mon, 11 Nov 2024 06:47:56 +0000 (22:47 -0800)
Doc/reference/compound_stmts.rst

index 1b1e9f479cbe0863312de5289223d279b7840ce2..e73ce44270b08214ff6e5be25f93b8658a51ae8b 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::