Skip to content

Commit 44740e5

Browse files
authored
Update checks for PEP 765 - return/break/continue in finally block (#10480)
1 parent ba26b71 commit 44740e5

File tree

16 files changed

+66
-24
lines changed

16 files changed

+66
-24
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
while True:
2+
try:
3+
pass
4+
finally:
5+
break # [break-in-finally]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
while True:
2+
try:
3+
pass
4+
except ValueError:
5+
pass
6+
else:
7+
break
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `Python 3 docs 'finally' clause <https://docs.python.org/3/reference/compound_stmts.html#finally-clause>`_
2+
- `PEP 765 - Disallow return/break/continue that exit a finally block <https://peps.python.org/pep-0765/>`_

doc/data/messages/c/continue-in-finally/details.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/data/messages/c/continue-in-finally/pylintrc

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `Python 3 docs 'finally' clause <https://docs.python.org/3/reference/compound_stmts.html#finally-clause>`_
2+
- `PEP 765 - Disallow return/break/continue that exit a finally block <https://peps.python.org/pep-0765/>`_
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- `Python 3 docs 'finally' clause <https://docs.python.org/3/reference/compound_stmts.html#finally-clause>`_
2+
- `PEP 765 - Disallow return/break/continue that exit a finally block <https://peps.python.org/pep-0765/>`_

doc/user_guide/checkers/features.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ Basic checker Messages
5757
Used when break or continue keywords are used outside a loop.
5858
:function-redefined (E0102): *%s already defined line %s*
5959
Used when a function / class / method is redefined.
60-
:continue-in-finally (E0116): *'continue' not supported inside 'finally' clause*
61-
Emitted when the `continue` keyword is found inside a finally clause, which
62-
is a SyntaxError.
6360
:abstract-class-instantiated (E0110): *Abstract class %r with abstract methods instantiated*
6461
Used when an abstract class with `abc.ABCMeta` as metaclass has abstract
6562
methods and is instantiated.
@@ -108,6 +105,12 @@ Basic checker Messages
108105
Used when a break or a return statement is found inside the finally clause of
109106
a try...finally block: the exceptions raised in the try clause will be
110107
silently swallowed instead of being re-raised.
108+
:break-in-finally (W0137): *'break' discouraged inside 'finally' clause*
109+
Emitted when the `break` keyword is found inside a finally clause. This
110+
will raise a SyntaxWarning starting in Python 3.14.
111+
:continue-in-finally (W0136): *'continue' discouraged inside 'finally' clause*
112+
Emitted when the `continue` keyword is found inside a finally clause. This
113+
will raise a SyntaxWarning starting in Python 3.14.
111114
:return-in-finally (W0134): *'return' shadowed by the 'finally' clause.*
112115
Emitted when a 'return' statement is found in a 'finally' block. This will
113116
overwrite the return value of a function and should be avoided.

doc/user_guide/messages/messages_overview.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ All messages in the error category:
6868
error/broken-noreturn
6969
error/catching-non-exception
7070
error/class-variable-slots-conflict
71-
error/continue-in-finally
7271
error/declare-non-slot
7372
error/dict-iter-missing-items
7473
error/duplicate-argument-name
@@ -223,13 +222,15 @@ All messages in the warning category:
223222
warning/bare-except
224223
warning/binary-op-exception
225224
warning/boolean-datetime
225+
warning/break-in-finally
226226
warning/broad-exception-caught
227227
warning/broad-exception-raised
228228
warning/cell-var-from-loop
229229
warning/comparison-with-callable
230230
warning/confusing-with-statement
231231
warning/consider-ternary-expression
232232
warning/contextmanager-generator-missing-cleanup
233+
warning/continue-in-finally
233234
warning/dangerous-default-value
234235
warning/deprecated-argument
235236
warning/deprecated-attribute

doc/whatsnew/fragments/10480.breaking

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The message-id of ``continue-in-finally`` was changed from ``E0116`` to ``W0136``. The warning is
2+
now emitted for every Python version since it will raise a syntax warning in Python 3.14.
3+
See `PEP 765 - Disallow return/break/continue that exit a finally block <https://peps.python.org/pep-0765/>`_.
4+
5+
Refs #10480

0 commit comments

Comments
 (0)