Skip to content

Commit

Permalink
[3.12] pythongh-126664: Use else instead of finally in "The with …
Browse files Browse the repository at this point in the history
…statement" documentation. (pythonGH-126665) (python#126671)

pythongh-126664: Use `else` instead of `finally` in "The with statement" documentation. (pythonGH-126665)
(cherry picked from commit 25257d6)

Co-authored-by: vivodi <103735539+vivodi@users.noreply.github.com>
  • Loading branch information
miss-islington and vivodi authored Nov 11, 2024
1 parent 7050aba commit fb82e10
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down

0 comments on commit fb82e10

Please sign in to comment.