diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-12-20 16:22:25 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-12-20 16:22:25 +0100 |
commit | 505554e9d09620b39bc3e31e7a55e636c805ad6e (patch) | |
tree | 40870a804b802066569cb122af25c93df12bc8d2 | |
parent | 1722f16ed58528768370ace7991ddaa70f3cbe3f (diff) | |
download | pylint-505554e9d09620b39bc3e31e7a55e636c805ad6e.tar.gz |
useless-else-on-loop not emited if there is a break in the else clause of inner loop. Close #117
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | checkers/base.py | 4 | ||||
-rw-r--r-- | test/input/func_useless_else_on_loop.py | 14 |
3 files changed, 29 insertions, 8 deletions
@@ -5,13 +5,13 @@ ChangeLog for Pylint * Add new check for use of deprecated pragma directives "pylint:disable-msg" or "pylint:enable-msg" (I0022, deprecated-pragma) which was previously - emmited as a regular warn() + emmited as a regular warn(). * Avoid false used-before-assignment for except handler defined - identifier used on the same line (#111) + identifier used on the same line (#111). * Combine 'no-space-after-operator', 'no-space-after-comma' and - 'no-space-before-operator' into a new warning 'bad-whitespace' + 'no-space-before-operator' into a new warning 'bad-whitespace'. * Add a new warning 'superfluous-parens' for unnecessary parentheses after certain keywords. @@ -25,18 +25,21 @@ ChangeLog for Pylint * Add 'bad-context-manager' error, checking that '__exit__' special method accepts the right number of arguments. - * Run pylint as a python module 'python -m pylint' (anatoly techtonik) + * Run pylint as a python module 'python -m pylint' (anatoly techtonik). - * Check for non-exception classes inside an except clause + * Check for non-exception classes inside an except clause. * epylint support options to give to pylint after the file to analyze and have basic input validation (bitbucket #53 and #54), patches provided by - felipeochoa and Brian Lane + felipeochoa and Brian Lane. * Added a new warning, 'non-iterator-returned', for non-iterators - returned by '__iter__' + returned by '__iter__'. - * Add new warning for unpacking non-sequences in assignments + * Add new warning for unpacking non-sequences in assignments. + + * useless-else-on-loop not emited if there is a break in the + else clause of inner loop (#117). 2013-08-06 -- 1.0.0 diff --git a/checkers/base.py b/checkers/base.py index 61ec528..2bbb6f7 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -79,6 +79,10 @@ def _loop_exits_early(loop): # in orelse. for child in loop.body: if isinstance(child, loop_nodes): + # break statement may be in orelse of child loop. + for orelse in (child.orelse or ()): + for _ in orelse.nodes_of_class(astroid.Break, skip_klass=loop_nodes): + return True continue for _ in child.nodes_of_class(astroid.Break, skip_klass=loop_nodes): return True diff --git a/test/input/func_useless_else_on_loop.py b/test/input/func_useless_else_on_loop.py index cec5a74..289366a 100644 --- a/test/input/func_useless_else_on_loop.py +++ b/test/input/func_useless_else_on_loop.py @@ -39,3 +39,17 @@ else: print 'fat chance' for j in range(10): break + +def test_return_for2(): + """no false positive for break in else + + https://bitbucket.org/logilab/pylint/issue/117/useless-else-on-loop-false-positives + """ + for i in range(10): + for i in range(i): + if i % 2: + break + else: + break + else: + print 'great math' |