-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir
Description
Documentation
In 8.5 The with
statement, we can use else
instead of finally
.
manager = (EXPRESSION)
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)
is semantically equivalent to:
manager = (EXPRESSION)
enter = type(manager).__enter__
exit = type(manager).__exit__
value = enter(manager)
try:
TARGET = value
SUITE
except:
if not exit(manager, *sys.exc_info()):
raise
else:
exit(manager, None, None, None)
Linked PRs
- gh-126664: Use
else
instead offinally
in "The with statement" documentation. #126665 - [3.13] gh-126664: Use
else
instead offinally
in "The with statement" documentation. (GH-126665) #126670 - [3.12] gh-126664: Use
else
instead offinally
in "The with statement" documentation. (GH-126665) #126671 - gh-126664: revert: Use
else
instead offinally
in docs explaining "with" #128169 - [3.13] gh-126664: revert: Use
else
instead offinally
in docs explaining "with" (GH-128169) #128170 - [3.12] gh-126664: revert: Use
else
instead offinally
in docs explaining "with" (GH-128169) #128171
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir
Projects
Status
Todo