Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-39037: Fix the trial order of the __exit__ and __enter__ methods in the with statement documentation #17608
+42
−12
Conversation
The else clause should instead be a finally clause to also handle the case when there is a non-local goto statement (break, continue, return) in suite (cf. https://stackoverflow.com/questions/59322585/what-is-the-exact-try-statement-equivalent-of-the-with-statement-in-python).
@@ -811,23 +834,26 @@ able to suspend execution in its *enter* and *exit* methods. | |||
|
|||
The following code:: | |||
|
|||
async with EXPR as VAR: | |||
BLOCK | |||
async with expression as target: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
raise | ||
else: | ||
await aexit(mgr, None, None, None) | ||
finally: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
maggyero
Dec 14, 2019
•
Author
Contributor
@serhiy-storchaka In order to also handle the case when there is a non-local goto statement (break
, continue
, return
) in the suite (cf. https://www.python.org/dev/peps/pep-0343/#specification-the-with-statement).
This comment has been minimized.
This comment has been minimized.
maggyero
Dec 15, 2019
Author
Contributor
@serhiy-storchaka But before knowing about PEP 343 I did the same mistake: https://stackoverflow.com/questions/59322585/what-is-the-exact-try-statement-equivalent-of-the-with-statement-in-python
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
maggyero commentedDec 14, 2019
•
edited
This PR will make these changes to the Compound statements chapter of the language documentation:
__exit__
and__enter__
methods in thewith
statement;try
statement of thewith
statement (it is already given for theasync with
statement);else
clause with afinally
clause in the equivalenttry
statement of theasync with
statement, in order to also handle the case when there is a non-local goto statement (break
,continue
,return
) in the suite (cf. https://stackoverflow.com/questions/59322585/what-is-the-exact-try-statement-equivalent-of-the-with-statement-in-python).https://bugs.python.org/issue39037