Skip to content

Commit 228f275

Browse files
authored
gh-126664: revert: Use else instead of finally in docs explaining "with" (#128169)
Revert "gh-126664: Use `else` instead of `finally` in "The with statement" documentation. (GH-126665)" This reverts commit 25257d6.
1 parent 8d9f52a commit 228f275

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,18 @@ is semantically equivalent to::
534534
enter = type(manager).__enter__
535535
exit = type(manager).__exit__
536536
value = enter(manager)
537+
hit_except = False
537538

538539
try:
539540
TARGET = value
540541
SUITE
541542
except:
543+
hit_except = True
542544
if not exit(manager, *sys.exc_info()):
543545
raise
544-
else:
545-
exit(manager, None, None, None)
546+
finally:
547+
if not hit_except:
548+
exit(manager, None, None, None)
546549

547550
With more than one item, the context managers are processed as if multiple
548551
:keyword:`with` statements were nested::

0 commit comments

Comments
 (0)