diff options
author | cpopa <devnull@localhost> | 2014-01-22 20:55:02 +0200 |
---|---|---|
committer | cpopa <devnull@localhost> | 2014-01-22 20:55:02 +0200 |
commit | 68829be83c2a6951350ef3a91f74c4bc052fcb40 (patch) | |
tree | 1fbe103f23cfb4d80893c9bfa9438879f78622a4 | |
parent | 3efbd7b18ac4ae194b308a1ef0eee1a97774f6f8 (diff) | |
download | pylint-68829be83c2a6951350ef3a91f74c4bc052fcb40.tar.gz |
Simplify check and enhance tests.
-rw-r--r-- | checkers/variables.py | 9 | ||||
-rw-r--r-- | test/input/func_used_before_assignment_py30.py | 9 | ||||
-rw-r--r-- | test/messages/func_used_before_assignment_py30.txt | 3 |
3 files changed, 14 insertions, 7 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index 6ab6927..f461319 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -510,12 +510,9 @@ builtins. Remember that you should avoid to define new builtins when possible.' else: # check if we have a nonlocal if name in defframe.locals: - for child in defframe.get_children(): - if not isinstance(child, astroid.Nonlocal): - continue - if name in child.names: - maybee0601 = False - break + maybee0601 = not any(isinstance(child, astroid.Nonlocal) + and name in child.names + for child in defframe.get_children()) if (maybee0601 and stmt.fromlineno <= defstmt.fromlineno and not is_defined_before(node) diff --git a/test/input/func_used_before_assignment_py30.py b/test/input/func_used_before_assignment_py30.py index 3765d6b..b5d0bf3 100644 --- a/test/input/func_used_before_assignment_py30.py +++ b/test/input/func_used_before_assignment_py30.py @@ -17,3 +17,12 @@ def test_fail(): def wrap():
cnt = cnt + 1
wrap()
+
+def test_fail2():
+ """ use nonlocal, but for other variable """
+ cnt = 1
+ count = 1
+ def wrap():
+ nonlocal count
+ cnt = cnt + 1
+ wrap()
diff --git a/test/messages/func_used_before_assignment_py30.txt b/test/messages/func_used_before_assignment_py30.txt index 21ee940..5b6080f 100644 --- a/test/messages/func_used_before_assignment_py30.txt +++ b/test/messages/func_used_before_assignment_py30.txt @@ -1 +1,2 @@ -E: 18:test_fail.wrap: Using variable 'cnt' before assignment
\ No newline at end of file +E: 18:test_fail.wrap: Using variable 'cnt' before assignment
+E: 27:test_fail2.wrap: Using variable 'cnt' before assignment
\ No newline at end of file |