-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
bpo-39037: Look up __enter__ before __exit__ 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).
@maggyero your PR is failing CI. Adding @ncoghlan as a reviewer since he probably is a good judge about the accuracy of the proposed clarification. |
@brettcannon Fixed, CI passed, thanks. |
Thanks @maggyero for the PR, and @ncoghlan for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
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 <[email protected]>
Thanks @serhiy-storchaka, @brettcannon and @ncoghlan for reviewing this PR! |
…ntation (pythonGH-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.
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