Skip to content
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

Further improve clarity of try-return-finally-return #17921

Open
wants to merge 4 commits into
base: master
from

Conversation

@toonarmycaptain
Copy link
Contributor

toonarmycaptain commented Jan 9, 2020

This stackoverflow question suggests that this explanation may be made clearer.

[This stackoverflow question](https://stackoverflow.com/questions/59639733/python-docs-have-misleading-explanation-of-return-in-finally) suggests that this explanation may be made clearer.
@toonarmycaptain

This comment has been minimized.

Copy link
Contributor Author

toonarmycaptain commented Jan 9, 2020

I has been suggested that

  • If a :keyword:finally clause includes a :keyword:return statement, the :keyword:finally clause's :keyword:return statement will execute instead of, the :keyword:return statement in a :keyword:try clause (but after the value of the :keyword:try clause's :keyword:return statement is evaluated).

Might be clearer if phrased simply

  • If both :keyword:try and :keyword:finally return a value, the :keyword:return value from the :keyword:finally block is returned.
A finally return statement is the last one executed in terms of evaluating the expression, but it is the *only* one executed in terms of returning a value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.