summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Matějka <jan+github@matejka.ninja>2018-12-04 14:40:47 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2018-12-04 14:40:47 +0100
commita499ab288bbba493803ac02920c652755805134c (patch)
tree29084c911d13a2524c91c01e7cc2a9e6354d6fd0
parenta0dfabc4206d100d92dffd6f15e48c7b5e98b8e9 (diff)
downloadpylint-git-a499ab288bbba493803ac02920c652755805134c.tar.gz
Fix false-postive undefined-variable in nested lambda. (#2274) (#2630)
Remove unnecessary break in checker utils for lambdas causing parent lambdas to be ignored. Close #760
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/utils.py1
-rw-r--r--pylint/test/unittest_checker_variables.py13
3 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 562ec2c9f..bec8831fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,10 @@ Release date: |TBA|
Close #1169
+ * Fix false-postive undefined-variable in nested lambda
+
+ Close #760
+
What's New in Pylint 1.9.3?
===========================
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 36f6e862c..ef6269e93 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -239,7 +239,6 @@ def is_defined_before(var_node):
return True
if getattr(_node, 'name', None) == varname:
return True
- break
elif isinstance(_node, astroid.ExceptHandler):
if isinstance(_node.name, astroid.AssignName):
ass_node = _node.name
diff --git a/pylint/test/unittest_checker_variables.py b/pylint/test/unittest_checker_variables.py
index 9bfabbba4..5e919d08d 100644
--- a/pylint/test/unittest_checker_variables.py
+++ b/pylint/test/unittest_checker_variables.py
@@ -180,6 +180,7 @@ class TestVariablesCheckerWithTearDown(CheckerTestCase):
with self.assertNoMessages():
self.walk(node)
+
def test_scope_in_defaults(self):
# Should not emit undefined variable
node = astroid.extract_node('''
@@ -201,6 +202,18 @@ class TestVariablesCheckerWithTearDown(CheckerTestCase):
with self.assertNoMessages():
self.walk(node)
+ def test_nested_lambda(self):
+ """Make sure variables from parent lambdas
+ aren't noted as undefined
+
+ https://github.com/PyCQA/pylint/issues/760
+ """
+ node = astroid.parse('''
+ lambda x: lambda: x + 1
+ ''')
+ with self.assertNoMessages():
+ self.walk(node)
+
class TestMissingSubmodule(CheckerTestCase):
CHECKER_CLASS = variables.VariablesChecker