Skip to content

Commit c95a195

Browse files
committed
add docs
1 parent e4151e6 commit c95a195

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ is executed. If there is a saved exception it is re-raised at the end of the
420420
:keyword:`!finally` clause. If the :keyword:`!finally` clause raises another
421421
exception, the saved exception is set as the context of the new exception.
422422
If the :keyword:`!finally` clause executes a :keyword:`return`, :keyword:`break`
423-
or :keyword:`continue` statement, the saved exception is discarded::
423+
or :keyword:`continue` statement, the saved exception is discarded.
424424

425425
>>> def f():
426426
... try:
@@ -461,6 +461,11 @@ always be the last one executed::
461461
Prior to Python 3.8, a :keyword:`continue` statement was illegal in the
462462
:keyword:`!finally` clause due to a problem with the implementation.
463463

464+
.. versionchanged:: 3.14
465+
The compiler emits a :exc:`SyntaxWarning` when a :keyword:`return`,
466+
:keyword:`break` or :keyword:`continue` appears in a :keyword:`!finally`
467+
block (see :pep:`765`).
468+
464469

465470
.. _with:
466471
.. _as:

Doc/tutorial/errors.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ points discuss more complex cases when an exception occurs:
417417

418418
* If the :keyword:`!finally` clause executes a :keyword:`break`,
419419
:keyword:`continue` or :keyword:`return` statement, exceptions are not
420-
re-raised.
420+
re-raised. This can be confusing and is therefore discouraged. From
421+
version 3.14 the compiler emits a :exc:`SyntaxWarning` for it
422+
(see :pep:`765`).
421423

422424
* If the :keyword:`!try` statement reaches a :keyword:`break`,
423425
:keyword:`continue` or :keyword:`return` statement, the
@@ -429,7 +431,9 @@ points discuss more complex cases when an exception occurs:
429431
statement, the returned value will be the one from the
430432
:keyword:`!finally` clause's :keyword:`!return` statement, not the
431433
value from the :keyword:`!try` clause's :keyword:`!return`
432-
statement.
434+
statement. This can be confusing and is therefore discouraged. From
435+
version 3.14 the compiler emits a :exc:`SyntaxWarning` for it
436+
(see :pep:`765`).
433437

434438
For example::
435439

Doc/whatsnew/3.14.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Summary -- release highlights
6868
* :ref:`PEP 741: Python Configuration C API <whatsnew314-pep741>`
6969
* :ref:`PEP 761: Discontinuation of PGP signatures <whatsnew314-pep761>`
7070
* :ref:`A new type of interpreter <whatsnew314-tail-call>`
71+
* :ref:`PEP 765: Disallow return/break/continue that exit a finally block <whatsnew314-pep765>`
7172

7273

7374
New features
@@ -305,6 +306,15 @@ Other language changes
305306
The testbed can also be used to run the test suite of projects other than
306307
CPython itself. (Contributed by Russell Keith-Magee in :gh:`127592`.)
307308

309+
.. _whatsnew314-pep765:
310+
311+
PEP 765: Disallow return/break/continue that exit a finally block
312+
-----------------------------------------------------------------
313+
314+
The compiler emits a ``SyntaxWarning`` when a ``return``, ``break`` or
315+
``continue`` statements appears where it exits a ``finally`` block.
316+
This change in is specified in :pep:`765`.
317+
308318
New modules
309319
===========
310320

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement PEP 765: Disallow return/break/continue that exit a finally block.

0 commit comments

Comments
 (0)