mirror of
https://github.com/python/cpython.git
synced 2025-08-19 16:20:59 +00:00
[3.12] gh-126664: Use else
instead of finally
in "The with statement" documentation. (GH-126665) (#126671)
gh-126664: Use `else` instead of `finally` in "The with statement" documentation. (GH-126665)
(cherry picked from commit 25257d61cf
)
Co-authored-by: vivodi <103735539+vivodi@users.noreply.github.com>
This commit is contained in:
parent
7050aba5d7
commit
fb82e10ce4
1 changed files with 2 additions and 5 deletions
|
@ -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::
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue