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 | b626280fe7b2eca2359441b85535846b41bad73f (patch) | |
| tree | 5903baa59e4ba059e2770b8b23545799e4e47ac0 /checkers/variables.py | |
| parent | 51c5dc1b89d899fa750440f11df6b561560826e4 (diff) | |
| download | pylint-git-b626280fe7b2eca2359441b85535846b41bad73f.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 8f8ee87a0..3b9bcda2c 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): |
