Message217277
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. |
|
Date |
User |
Action |
Args |
2014-04-27 16:12:19 | brandjon | set | recipients:
+ brandjon, docs@python |
2014-04-27 16:12:19 | brandjon | set | messageid: <1398615139.09.0.290952002497.issue21366@psf.upfronthosting.co.za> |
2014-04-27 16:12:19 | brandjon | link | issue21366 messages |
2014-04-27 16:12:18 | brandjon | create | |
|