diff options
author | Fantix King <fantix@uchicago.edu> | 2019-02-20 14:42:13 -0600 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-02-22 18:09:53 +0100 |
commit | 15e405f20c9432f50c677a4026adc76124716861 (patch) | |
tree | 57b996ff4d6c24c896e261eb610437e7bd42bd1a | |
parent | 8c1116851fadf3f46f9ad2ce7fcbfb5acdf36da3 (diff) | |
download | pylint-git-15e405f20c9432f50c677a4026adc76124716861.tar.gz |
Fix bug of W0120
When break is deep in the else of an inner loop, W0120 was raised.
-rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | pylint/checkers/base.py | 1 | ||||
-rw-r--r-- | pylint/test/functional/useless_else_on_loop.py | 3 | ||||
-rw-r--r-- | pylint/test/functional/useless_else_on_loop.txt | 2 |
5 files changed, 9 insertions, 2 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index fc905aeaa..4a4336afd 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -269,3 +269,5 @@ contributors: * Svetoslav Neykov: contributor * Federico Bond: contributor + +* Fantix King (UChicago): contributor @@ -136,6 +136,9 @@ Release date: TBA * Fix false positive ``not-callable`` for uninferable properties. +* Fix false positive ``useless-else-on-loop`` if the break is deep in the else + of an inner loop. + What's New in Pylint 2.2.2? =========================== diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index 05de23ef8..043700f02 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -246,6 +246,7 @@ def _get_break_loop_node(break_node): while not isinstance(parent, loop_nodes) or break_node in getattr( parent, "orelse", [] ): + break_node = parent parent = parent.parent if parent is None: break diff --git a/pylint/test/functional/useless_else_on_loop.py b/pylint/test/functional/useless_else_on_loop.py index 465f659f9..8fd178798 100644 --- a/pylint/test/functional/useless_else_on_loop.py +++ b/pylint/test/functional/useless_else_on_loop.py @@ -67,7 +67,8 @@ def test_break_in_orelse_deep(): if 3 < 2: break else: - break + if 1 < 2: + break else: return True return False diff --git a/pylint/test/functional/useless_else_on_loop.txt b/pylint/test/functional/useless_else_on_loop.txt index efa1161ab..0d561011f 100644 --- a/pylint/test/functional/useless_else_on_loop.txt +++ b/pylint/test/functional/useless_else_on_loop.txt @@ -3,4 +3,4 @@ useless-else-on-loop:18:test_return_while:Else clause on loop without a break st useless-else-on-loop:28::Else clause on loop without a break statement useless-else-on-loop:35::Else clause on loop without a break statement useless-else-on-loop:40::Else clause on loop without a break statement -useless-else-on-loop:87:test_break_in_orelse_deep2:Else clause on loop without a break statement +useless-else-on-loop:88:test_break_in_orelse_deep2:Else clause on loop without a break statement |