summaryrefslogtreecommitdiff
path: root/pylint/checkers/variables.py
diff options
context:
space:
mode:
authorBryce Guinta <bryce.paul.guinta@gmail.com>2018-02-26 23:31:38 -0700
committerBryce Guinta <bryce.paul.guinta@gmail.com>2018-03-02 22:52:58 -0700
commitc71433d13a7f884cbda48da7b812da42078761fb (patch)
tree0e45ef954c53c6dad8c8d4a1167327aaa2214a93 /pylint/checkers/variables.py
parent2ad80d92f5e381bda2a7b40e1ee4a81605c7287a (diff)
downloadpylint-git-c71433d13a7f884cbda48da7b812da42078761fb.tar.gz
Fix false positive undefined-variable for lambda arguments in classes
Close #1824
Diffstat (limited to 'pylint/checkers/variables.py')
-rw-r--r--pylint/checkers/variables.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 9d856c3b3..4af7f53bb 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -961,6 +961,10 @@ class VariablesChecker(BaseChecker):
def _is_variable_violation(node, name, defnode, stmt, defstmt,
frame, defframe, base_scope_type,
recursive_klass):
+ # node: Node to check for violation
+ # name: name of node to check violation for
+ # frame: Scope of statement of node
+ # base_scope_type: local scope type
maybee0601 = True
annotation_return = False
use_outer_definition = False
@@ -974,8 +978,13 @@ class VariablesChecker(BaseChecker):
else:
# we are in a local scope, check the name is not
# defined in global or builtin scope
- # skip this lookup if name is assigned later in function scope
- forbid_lookup = isinstance(frame, astroid.FunctionDef) and _assigned_locally(node)
+ # skip this lookup if name is assigned later in function scope/lambda
+ # Note: the node.frame() is not the same as the `frame` argument which is
+ # equivalent to frame.statement().scope()
+ forbid_lookup = ((isinstance(frame, astroid.FunctionDef) or
+ isinstance(node.frame(), astroid.Lambda)) and
+ _assigned_locally(node))
+
if not forbid_lookup and defframe.root().lookup(name)[1]:
maybee0601 = False
use_outer_definition = (