diff options
author | Torsten Marek <shlomme@gmail.com> | 2014-07-25 10:42:41 +0200 |
---|---|---|
committer | Torsten Marek <shlomme@gmail.com> | 2014-07-25 10:42:41 +0200 |
commit | 3b44ac5a6f38449e50153768f10fd1c1985608a0 (patch) | |
tree | b45cf35d474090078b7aefb058a597edb34cbf63 /checkers/variables.py | |
parent | 567fb4030d5ab12ccaf5d19f5cfbf35c44bc95de (diff) | |
download | pylint-3b44ac5a6f38449e50153768f10fd1c1985608a0.tar.gz |
Fix more edge cases in the cell-var-from-loop warning (Closes: #233).
Diffstat (limited to 'checkers/variables.py')
-rw-r--r-- | checkers/variables.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index 8f8ee87..3b9bcda 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -542,9 +542,15 @@ builtins. Remember that you should avoid to define new builtins when possible.' self.add_message('global-statement', node=node) def _check_late_binding_closure(self, node, assignment_node, scope_type): + def _is_direct_lambda_call(): + return (isinstance(node_scope.parent, astroid.CallFunc) + and node_scope.parent.func is node_scope) + node_scope = node.scope() if not isinstance(node_scope, (astroid.Lambda, astroid.Function)): return + if isinstance(node.parent, astroid.Arguments): + return if isinstance(assignment_node, astroid.Comprehension): if assignment_node.parent.parent_of(node.scope()): @@ -557,7 +563,9 @@ builtins. Remember that you should avoid to define new builtins when possible.' break maybe_for = maybe_for.parent else: - if maybe_for.parent_of(node_scope) and not isinstance(node_scope.statement(), astroid.Return): + if (maybe_for.parent_of(node_scope) + and not _is_direct_lambda_call() + and not isinstance(node_scope.statement(), astroid.Return)): self.add_message('cell-var-from-loop', node=node, args=node.name) def _loopvar_name(self, node, name): |