-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Improve clarity of try-return-finally-return #15677
Conversation
Clarify execution in try-return-finally-return case.
Add my name to ACKS
Remove trailing whitespace.
Co-Authored-By: Ashwin Ramaswami <aramaswamis@gmail.com>
@epicfaace requested including example referred to [on discuss](https://discuss.python.org/t/pep-601-forbid-return-break-continue-breaking-out-of-finally/2239/3?u=toonarmycaptain).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @toonarmycaptain, thanks for the PR. I have left some suggested wording to help be more explicit and user friendly in tone for this tutorial.
Doc/tutorial/errors.rst
Outdated
when any other clause of the :keyword:`!try` statement is left via a | ||
:keyword:`break`, :keyword:`continue` or :keyword:`return` statement. A more | ||
complicated example:: | ||
:keyword:`!else` clause), it is re-raised after the :keyword:`!finally` clause has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a tutorial, I would recommend being explicit with a direct tone and minimal jargon. Some suggestions for change of this PR:
If a :keyword:finally
clause is present, the :keyword:finally
clause will execute as the last task before the :keyword:try
statement completes. The :keyword:finally
clause runs whether or not the :keyword:try
statement produces an exception. The following points discuss more complex cases when an exception occurs:
-
If an exception occurs during execution of the :keyword:
!try
clause, the exception may be handled by an :keyword:except
clause. In all cases, the exception is re-raised after the :keyword::
!finally` clause has been executed. -
An exception could occur during execution of an :keyword:
!except
or :keyword:!else
clause. Again, the exception is re-raised after the :keyword::
!finally` clause has been executed. -
If the :keyword:
!try
statement reaches a :keyword:break
, :keyword:continue
or :keyword:return
statement, the :keyword:finally
clause will execute just prior to the :keyword:break
, :keyword:continue
or :keyword:return
statement's execution. -
If a :keyword:
finally
clause includes a :keyword:return
statement, the :keyword:finally
clause's :keyword:return
statement will execute before, and instead of, the :keyword:return
statement in a :keyword:try
clause.
For example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks and let me know if you need any clarification on the suggested changes.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Clarify language with regard to tone/jargon and formatting [per @willingc](https://github.com/python/cpython/pull/15677/files#r323079139).
I believe I have made the requested changes; please review again. |
Thanks for making the requested changes! @willingc: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @toonarmycaptain. Just waiting for CI to pass.
Thanks @toonarmycaptain for the PR, and @matrixise for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8. |
Clarify execution in try-return-finally-return case. (cherry picked from commit 0cc2741) Co-authored-by: toonarmycaptain <toonarmycaptain@hotmail.com>
GH-15981 is a backport of this pull request to the 3.8 branch. |
Clarify execution in try-return-finally-return case. (cherry picked from commit 0cc2741) Co-authored-by: toonarmycaptain <toonarmycaptain@hotmail.com>
GH-15982 is a backport of this pull request to the 3.7 branch. |
https://bugs.python.org/issue38130 was filed a little bit ago stemming from this PR. Could the original author or one of the reviewers please take a look :) |
Clarify execution in try-return-finally-return case.
Clarify execution of try-return-finally-return case.
Per discussion https://discuss.python.org/t/pep-601-forbid-return-break-continue-breaking-out-of-finally