]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126664: revert: Use `else` instead of `finally` in docs explaining "with" (#128169)
authorGregory P. Smith <greg@krypto.org>
Sun, 22 Dec 2024 09:47:41 +0000 (01:47 -0800)
committerGitHub <noreply@github.com>
Sun, 22 Dec 2024 09:47:41 +0000 (09:47 +0000)
Revert "gh-126664: Use `else` instead of `finally` in "The with statement" documentation. (GH-126665)"

This reverts commit 25257d61cfccc3b4189f96390a5c4db73fd5302c.

Doc/reference/compound_stmts.rst

index e73ce44270b08214ff6e5be25f93b8658a51ae8b..1b1e9f479cbe0863312de5289223d279b7840ce2 100644 (file)
@@ -534,15 +534,18 @@ 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
-    else:
-        exit(manager, None, None, None)
+    finally:
+        if not hit_except:
+            exit(manager, None, None, None)
 
 With more than one item, the context managers are processed as if multiple
 :keyword:`with` statements were nested::