summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Ware <zachary.ware@gmail.com>2014-05-06 09:07:51 -0500
committerZachary Ware <zachary.ware@gmail.com>2014-05-06 09:07:51 -0500
commit4e6688d2b29183cae7796b2459a5b87143c3e36f (patch)
tree6b800904a2e1140657d5f465f0a61a96dd66fd91
parentb8ac3e1a205c79a37dbb7365a87b498e194eebdd (diff)
parent8edd532026c10816e055b14d5999b6d93540fc6e (diff)
downloadcpython-git-4e6688d2b29183cae7796b2459a5b87143c3e36f.tar.gz
Issue #21366: Document the fact that ``return`` in a ``finally`` clause
overrides a ``return`` in the ``try`` suite.
-rw-r--r--Doc/reference/compound_stmts.rst14
1 files changed, 14 insertions, 0 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 4e037113fb..869eef4924 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -337,6 +337,20 @@ statement, the :keyword:`finally` clause is also executed 'on the way out.' A
reason is a problem with the current implementation --- this restriction may be
lifted in the future).
+The return value of a function is determined by the last :keyword:`return`
+statement executed. Since the :keyword:`finally` clause always executes, a
+:keyword:`return` statement executed in the :keyword:`finally` clause will
+always be the last one executed::
+
+ >>> def foo():
+ ... try:
+ ... return 'try'
+ ... finally:
+ ... return 'finally'
+ ...
+ >>> foo()
+ 'finally'
+
Additional information on exceptions can be found in section :ref:`exceptions`,
and information on using the :keyword:`raise` statement to generate exceptions
may be found in section :ref:`raise`.