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
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).
Doc/reference/compound_stmts.rst
Outdated
@@ -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.
This comment has been minimized.
This comment has been minimized.
brettcannon
Dec 16, 2019
Member
It's not important to match the grammar in this case as the docs are not kept in sync with the grammar rule names.
This comment has been minimized.
This comment has been minimized.
ncoghlan
Dec 18, 2019
Contributor
Right, we deliberately use ALL_CAPS in these semantic expansions to distinguish the placeholders from keywords and hidden variables.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@brettcannon Fixed, CI passed, thanks. |
This comment has been minimized.
This comment has been minimized.
miss-islington
commented
Dec 30, 2019
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Dec 30, 2019
GH-17749 is a backport of this pull request to the 3.8 branch. |
miss-islington
added a commit
that referenced
this pull request
Dec 30, 2019
…ntation (GH-17608) * __enter__ is now looked up before __exit__ to give a more intuitive error message * add pseudo-code equivalent for the with statement * fix pseudo-code for the async with statement to use a finally clause * use SUITE rather than BLOCK for consistency with the language grammar Patch by Géry Ogam. (cherry picked from commit 226e6e7) Co-authored-by: Géry Ogam <gery.ogam@gmail.com>
This comment has been minimized.
This comment has been minimized.
Thanks @serhiy-storchaka, @brettcannon and @ncoghlan for reviewing this PR! |
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 (since 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