This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brandjon
Recipients brandjon, docs@python
Date 2014-04-27.16:12:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1398615139.09.0.290952002497.issue21366@psf.upfronthosting.co.za>
In-reply-to
Content
def foo():
    try:
      return 1
    finally;
      return 2
  print(foo())  # 2

I've seen this peculiar case discussed on a few blogs lately, but was unable to find confirmation that this behavior is defined.

In the try/finally section of Doc/reference/compound_stmts.rst, immediately after the sentence beginning

> When a return, break, or continue statement is executed

I propose adding something to the effect of:

> A return statement in a finally clause overrides the value of any return statement executed in the try suite.

This wording also handles the case of nested try/finally blocks.
History
Date User Action Args
2014-04-27 16:12:19brandjonsetrecipients: + brandjon, docs@python
2014-04-27 16:12:19brandjonsetmessageid: <1398615139.09.0.290952002497.issue21366@psf.upfronthosting.co.za>
2014-04-27 16:12:19brandjonlinkissue21366 messages
2014-04-27 16:12:18brandjoncreate