diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-03-18 07:56:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-18 07:56:52 (GMT) |
commit | fe2bbb1869b42222a3f331a3dfb8b304a19a5819 (patch) | |
tree | 0f9e51eb7b9dbfab1d92a1538cef297081a46b55 /Doc/reference | |
parent | 134cb01cda50f02725575808130b05d2d776693f (diff) | |
download | cpython-fe2bbb1869b42222a3f331a3dfb8b304a19a5819.zip cpython-fe2bbb1869b42222a3f331a3dfb8b304a19a5819.tar.gz cpython-fe2bbb1869b42222a3f331a3dfb8b304a19a5819.tar.bz2 |
bpo-32489: Allow 'continue' in 'finally' clause. (GH-5822)
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/compound_stmts.rst | 13 | ||||
-rw-r--r-- | Doc/reference/simple_stmts.rst | 5 |
2 files changed, 9 insertions, 9 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index d7792f1..153e85b 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -321,8 +321,8 @@ not handled, the exception is temporarily saved. The :keyword:`finally` clause is executed. If there is a saved exception it is re-raised at the end of the :keyword:`finally` clause. If the :keyword:`finally` clause raises another exception, the saved exception is set as the context of the new exception. -If the :keyword:`finally` clause executes a :keyword:`return` or :keyword:`break` -statement, the saved exception is discarded:: +If the :keyword:`finally` clause executes a :keyword:`return`, :keyword:`break` +or :keyword:`continue` statement, the saved exception is discarded:: >>> def f(): ... try: @@ -343,10 +343,7 @@ the :keyword:`finally` clause. When a :keyword:`return`, :keyword:`break` or :keyword:`continue` statement is executed in the :keyword:`try` suite of a :keyword:`try`...\ :keyword:`finally` -statement, the :keyword:`finally` clause is also executed 'on the way out.' A -:keyword:`continue` statement is illegal in the :keyword:`finally` clause. (The -reason is a problem with the current implementation --- this restriction may be -lifted in the future). +statement, the :keyword:`finally` clause is also executed 'on the way out.' The return value of a function is determined by the last :keyword:`return` statement executed. Since the :keyword:`finally` clause always executes, a @@ -366,6 +363,10 @@ 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`. +.. versionchanged:: 3.8 + Prior to Python 3.8, a :keyword:`continue` statement was illegal in the + :keyword:`finally` clause due to a problem with the implementation. + .. _with: .. _as: diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index ef9a5f0..9186210 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -686,9 +686,8 @@ The :keyword:`continue` statement continue_stmt: "continue" :keyword:`continue` may only occur syntactically nested in a :keyword:`for` or -:keyword:`while` loop, but not nested in a function or class definition or -:keyword:`finally` clause within that loop. It continues with the next -cycle of the nearest enclosing loop. +:keyword:`while` loop, but not nested in a function or class definition within +that loop. It continues with the next cycle of the nearest enclosing loop. When :keyword:`continue` passes control out of a :keyword:`try` statement with a :keyword:`finally` clause, that :keyword:`finally` clause is executed before |