[issue21366] Document that return in finally overwrites prev value
Jon Brandvein
report at bugs.python.org
Sun Apr 27 18:12:19 CEST 2014
New submission from Jon Brandvein:
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.
----------
assignee: docs at python
components: Documentation
messages: 217277
nosy: brandjon, docs at python
priority: normal
severity: normal
status: open
title: Document that return in finally overwrites prev value
type: behavior
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21366>
_______________________________________
More information about the Python-bugs-list
mailing list