Skip to content

Commit 4d3ad96

Browse files
authored
Clarify no-else-raise and no-else-return also apply to try/except (#10002)
1 parent c25923f commit 4d3ad96

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

doc/user_guide/checkers/features.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -891,13 +891,15 @@ Refactoring checker Messages
891891
containing a continue statement. As such, it will warn when it encounters an
892892
else following a chain of ifs, all of them containing a continue statement.
893893
:no-else-raise (R1720): *Unnecessary "%s" after "raise", %s*
894-
Used in order to highlight an unnecessary block of code following an if
895-
containing a raise statement. As such, it will warn when it encounters an
896-
else following a chain of ifs, all of them containing a raise statement.
894+
Used in order to highlight an unnecessary block of code following an if, or a
895+
try/except containing a raise statement. As such, it will warn when it
896+
encounters an else following a chain of ifs, all of them containing a raise
897+
statement.
897898
:no-else-return (R1705): *Unnecessary "%s" after "return", %s*
898-
Used in order to highlight an unnecessary block of code following an if
899-
containing a return statement. As such, it will warn when it encounters an
900-
else following a chain of ifs, all of them containing a return statement.
899+
Used in order to highlight an unnecessary block of code following an if, or a
900+
try/except containing a return statement. As such, it will warn when it
901+
encounters an else following a chain of ifs, all of them containing a return
902+
statement.
901903
:unnecessary-dict-index-lookup (R1733): *Unnecessary dictionary index lookup, use '%s' instead*
902904
Emitted when iterating over the dictionary items (key-item pairs) and
903905
accessing the value by index lookup. The value can be accessed directly

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
285285
'Unnecessary "%s" after "return", %s',
286286
"no-else-return",
287287
"Used in order to highlight an unnecessary block of "
288-
"code following an if containing a return statement. "
288+
"code following an if, or a try/except containing a return statement. "
289289
"As such, it will warn when it encounters an else "
290290
"following a chain of ifs, all of them containing a "
291291
"return statement.",
@@ -387,7 +387,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
387387
'Unnecessary "%s" after "raise", %s',
388388
"no-else-raise",
389389
"Used in order to highlight an unnecessary block of "
390-
"code following an if containing a raise statement. "
390+
"code following an if, or a try/except containing a raise statement. "
391391
"As such, it will warn when it encounters an else "
392392
"following a chain of ifs, all of them containing a "
393393
"raise statement.",

0 commit comments

Comments
 (0)