Skip to content

Commit 25257d6

Browse files
authored
gh-126664: Use else instead of finally in "The with statement" documentation. (GH-126665)
1 parent 5c488ca commit 25257d6

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Doc/reference/compound_stmts.rst

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

539538
try:
540539
TARGET = value
541540
SUITE
542541
except:
543-
hit_except = True
544542
if not exit(manager, *sys.exc_info()):
545543
raise
546-
finally:
547-
if not hit_except:
548-
exit(manager, None, None, None)
544+
else:
545+
exit(manager, None, None, None)
549546

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

0 commit comments

Comments
 (0)