]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-126664: revert: Use `else` instead of `finally` in docs explaining "with...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 24 Dec 2024 18:55:57 +0000 (19:55 +0100)
committerGitHub <noreply@github.com>
Tue, 24 Dec 2024 18:55:57 +0000 (10:55 -0800)
gh-126664: revert: Use `else` instead of `finally` in docs explaining "with" (GH-128169)

Revert "gh-126664: Use `else` instead of `finally` in "The with statement" documentation. (GH-126665)"

This reverts commit 25257d61cfccc3b4189f96390a5c4db73fd5302c.
(cherry picked from commit 228f275737615cc9be713a8c3f9325b359bf8aec)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Doc/reference/compound_stmts.rst

index 69c47686dd67845a797d57e21df9c4bc763fb977..c7e43ef773907ac9ec881850b622d83682c8b71e 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::