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@python
components: Documentation
messages: 217277
nosy: brandjon, docs@python
priority: normal
severity: normal
status: open
title: Document that return in finally overwrites prev value
type: behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21366>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to