diff options
-rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | pylint/checkers/base.py | 6 | ||||
-rw-r--r-- | pylint/test/functional/nonlocal_without_binding.py | 4 |
4 files changed, 13 insertions, 4 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index e88762a..518a7a0 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -68,3 +68,5 @@ Order doesn't matter (not that much, at least ;) by their feedback or even patches, if I've forgotten you, send me a note ! * Cezar Elnazli: deprecated-method + +* Stéphane Wirtel: nonlocal-without-binding @@ -295,6 +295,11 @@ ChangeLog for Pylint for --load-plugins never actually worked, while it also didn't raise an error. Closes issue #424. + * Add a new error, 'nonlocal-without-binding' + + The error is emitted on Python 3 when a nonlocal name is not bound + to any variable in the parents scopes. Closes issue #582. + 2015-03-14 -- 1.4.3 diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index 38cf0ab..70fa2e1 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -330,7 +330,8 @@ class BasicErrorChecker(_BasicChecker): 'inside a finally clause, which is a SyntaxError.'), 'E0117': ("nonlocal variable without binding", 'nonlocal-without-binding', - 'Emitted when a nonlocal variable is not bound', + 'Emitted when a nonlocal variable does not have an attached ' + 'name somewhere in the parent scopes', {'minversion': (3, 0)}), } @@ -464,12 +465,13 @@ class BasicErrorChecker(_BasicChecker): if not isinstance(current_scope, astroid.FunctionDef): self.add_message('nonlocal-without-binding', node=node) - break + return else: if name not in current_scope.locals: current_scope = current_scope.parent.scope() continue else: + # Okay, found it. return self.add_message('nonlocal-without-binding', node=node) diff --git a/pylint/test/functional/nonlocal_without_binding.py b/pylint/test/functional/nonlocal_without_binding.py index 2871ed6..16cfd14 100644 --- a/pylint/test/functional/nonlocal_without_binding.py +++ b/pylint/test/functional/nonlocal_without_binding.py @@ -1,6 +1,6 @@ """ Checks that reversed() receive proper argument """ -# pylint: disable=missing-docstring -# pylint: disable=too-few-public-methods,no-self-use,no-absolute-import,invalid-name,unused-variable +# pylint: disable=missing-docstring,invalid-name,unused-variable +# pylint: disable=too-few-public-methods,no-self-use,no-absolute-import def test(): def parent(): |