File tree Expand file tree Collapse file tree 4 files changed +23
-3
lines changed
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree 4 files changed +23
-3
lines changed Original file line number Diff line number Diff 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
421421exception, the saved exception is set as the context of the new exception.
422422If 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 :
Original file line number Diff line number Diff 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
434438For example::
435439
Original file line number Diff line number Diff 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
7374New 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+
308318New modules
309319===========
310320
Original file line number Diff line number Diff line change 1+ Implement PEP 765: Disallow return/break/continue that exit a finally block.
You can’t perform that action at this time.
0 commit comments