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).
@@ -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.
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 To 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). Before knowing about PEP 343 I did the same mistake (cf. https://stackoverflow.com/questions/59322585/what-is-the-exact-try-statement-equivalent-of-the-with-statement-in-python).
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. |
…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>
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