diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2017-10-12 10:29:01 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2017-10-12 10:29:01 +0200 |
commit | b26ad09d1aeccae53d474fe5fe30f5053fc3c9d9 (patch) | |
tree | 23dbe5475625189aa81bff8d07ab0a99b4fc6caf | |
parent | 8a5fb98e633347c6b0755735891a4ef2d26c3e7c (diff) | |
download | pylint-git-b26ad09d1aeccae53d474fe5fe30f5053fc3c9d9.tar.gz |
Use any() instead of checking the value of an entire list
-rw-r--r-- | pylint/checkers/base.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index ea899ea7f..8182d6533 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -204,6 +204,7 @@ def _get_break_loop_node(break_node): break return parent + def _loop_exits_early(loop): """ Returns true if a loop may ends up in a break statement. @@ -216,15 +217,16 @@ def _loop_exits_early(loop): """ loop_nodes = (astroid.For, astroid.While) definition_nodes = (astroid.FunctionDef, astroid.ClassDef) - inner_loop_nodes = [_node for _node in loop.nodes_of_class(loop_nodes, - skip_klass=definition_nodes) - if _node != loop] - inner_break_nodes = [_node for _node in loop.nodes_of_class(astroid.Break, - skip_klass=definition_nodes) - if _get_break_loop_node(_node) not in inner_loop_nodes] - if inner_break_nodes: - return True - return False + inner_loop_nodes = [ + _node for _node in loop.nodes_of_class(loop_nodes, + skip_klass=definition_nodes) + if _node != loop + ] + return any( + _node for _node in loop.nodes_of_class(astroid.Break, + skip_klass=definition_nodes) + if _get_break_loop_node(_node) not in inner_loop_nodes + ) def _is_multi_naming_match(match, node_type, confidence): |