Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use else instead of finally in "The with statement" documentation. #126664

Closed
vivodi opened this issue Nov 11, 2024 · 3 comments
Closed

Use else instead of finally in "The with statement" documentation. #126664

vivodi opened this issue Nov 11, 2024 · 3 comments
Labels
docs Documentation in the Doc dir

Comments

@vivodi
Copy link
Contributor

vivodi commented Nov 11, 2024

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

@vivodi vivodi added the docs Documentation in the Doc dir label Nov 11, 2024
gpshead pushed a commit that referenced this issue Nov 11, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 11, 2024
…nt" documentation. (pythonGH-126665)

(cherry picked from commit 25257d6)

Co-authored-by: vivodi <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 11, 2024
…nt" documentation. (pythonGH-126665)

(cherry picked from commit 25257d6)

Co-authored-by: vivodi <[email protected]>
gpshead pushed a commit that referenced this issue Nov 11, 2024
…ent" documentation. (GH-126665) (#126670)

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

Co-authored-by: vivodi <[email protected]>
gpshead pushed a commit that referenced this issue Nov 11, 2024
…ent" documentation. (GH-126665) (#126671)

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

Co-authored-by: vivodi <[email protected]>
@nineteendo
Copy link
Contributor

You should be able to close this now.

@skirpichev
Copy link
Member

Yeah, all merged.

picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 8, 2024
gpshead added a commit to gpshead/cpython that referenced this issue Dec 22, 2024
… statement" documentation. (pythonGH-126665)"

This reverts commit 25257d6.
@gpshead
Copy link
Member

gpshead commented Dec 22, 2024

reverting these per #126665 (comment)

gpshead added a commit that referenced this issue Dec 22, 2024
… "with" (#128169)

Revert "gh-126664: Use `else` instead of `finally` in "The with statement" documentation. (GH-126665)"

This reverts commit 25257d6.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 22, 2024
…aining "with" (pythonGH-128169)

Revert "pythongh-126664: Use `else` instead of `finally` in "The with statement" documentation. (pythonGH-126665)"

This reverts commit 25257d6.
(cherry picked from commit 228f275)

Co-authored-by: Gregory P. Smith <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 22, 2024
…aining "with" (pythonGH-128169)

Revert "pythongh-126664: Use `else` instead of `finally` in "The with statement" documentation. (pythonGH-126665)"

This reverts commit 25257d6.
(cherry picked from commit 228f275)

Co-authored-by: Gregory P. Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

4 participants