summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-09-21 23:20:56 +0000
committerClaudiu Popa <pcmanticore@gmail.com>2015-09-21 23:20:56 +0000
commit1b1a8084a3afd30134f8482f0c8de40750ee670f (patch)
tree5633c6eb2b06d39a90c722b8a7b74d93df5f1c61
parentd320ea5a84ae730dc3b10a43f571c9bc9b98b92a (diff)
downloadpylint-1b1a8084a3afd30134f8482f0c8de40750ee670f.tar.gz
Show what nonlocal was found without a binding.
-rw-r--r--pylint/checkers/base.py7
-rw-r--r--pylint/test/functional/nonlocal_without_binding.py10
-rw-r--r--pylint/test/functional/nonlocal_without_binding.txt4
3 files changed, 17 insertions, 4 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 70fa2e1..8b2c650 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -328,7 +328,7 @@ class BasicErrorChecker(_BasicChecker):
'continue-in-finally',
'Emitted when the `continue` keyword is found '
'inside a finally clause, which is a SyntaxError.'),
- 'E0117': ("nonlocal variable without binding",
+ 'E0117': ("nonlocal name %s found without binding",
'nonlocal-without-binding',
'Emitted when a nonlocal variable does not have an attached '
'name somewhere in the parent scopes',
@@ -464,7 +464,8 @@ class BasicErrorChecker(_BasicChecker):
break
if not isinstance(current_scope, astroid.FunctionDef):
- self.add_message('nonlocal-without-binding', node=node)
+ self.add_message('nonlocal-without-binding', args=(name, ),
+ node=node)
return
else:
if name not in current_scope.locals:
@@ -474,7 +475,7 @@ class BasicErrorChecker(_BasicChecker):
# Okay, found it.
return
- self.add_message('nonlocal-without-binding', node=node)
+ self.add_message('nonlocal-without-binding', args=(name, ), node=node)
@check_messages('nonlocal-without-binding')
def visit_nonlocal(self, node):
diff --git a/pylint/test/functional/nonlocal_without_binding.py b/pylint/test/functional/nonlocal_without_binding.py
index 16cfd14..0501dd8 100644
--- a/pylint/test/functional/nonlocal_without_binding.py
+++ b/pylint/test/functional/nonlocal_without_binding.py
@@ -8,13 +8,23 @@ def test():
def stuff():
nonlocal a
+ c = 24
def parent2():
a = 42
def stuff():
def other_stuff():
nonlocal a
+ nonlocal c
b = 42
def func():
def other_func():
nonlocal b # [nonlocal-without-binding]
+
+class SomeClass(object):
+ nonlocal x # [nonlocal-without-binding]
+
+ def func(self):
+ nonlocal some_attr # [nonlocal-without-binding]
+
+ \ No newline at end of file
diff --git a/pylint/test/functional/nonlocal_without_binding.txt b/pylint/test/functional/nonlocal_without_binding.txt
index 17a40ac..05a1105 100644
--- a/pylint/test/functional/nonlocal_without_binding.txt
+++ b/pylint/test/functional/nonlocal_without_binding.txt
@@ -1 +1,3 @@
-nonlocal-without-binding:20:func.other_func:nonlocal variable without binding \ No newline at end of file
+nonlocal-without-binding:22:func.other_func:nonlocal name b found without binding
+nonlocal-without-binding:25:SomeClass:nonlocal name x found without binding
+nonlocal-without-binding:28:SomeClass.func:nonlocal name some_attr found without binding \ No newline at end of file