Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 228f275

Browse filesBrowse 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
Copy full SHA for 228f275

File tree

1 file changed

+5
-2
lines changed
Filter options

1 file changed

+5
-2
lines changed

‎Doc/reference/compound_stmts.rst

Copy file name to clipboardExpand all lines: Doc/reference/compound_stmts.rst
+5-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.