diff options
author | cpopa <devnull@localhost> | 2014-07-23 13:17:29 +0200 |
---|---|---|
committer | cpopa <devnull@localhost> | 2014-07-23 13:17:29 +0200 |
commit | 1df3bf598b0f5256802cb1d5486be3bffde20632 (patch) | |
tree | 7cdaaee0c918afdbd8eef647f836e3b4e79ca159 /checkers | |
parent | d2dac2c5d2ba2f8a06fe43d815fd3ff63a089000 (diff) | |
download | pylint-1df3bf598b0f5256802cb1d5486be3bffde20632.tar.gz |
Don't emit 'unused-variable' when assigning to a nonlocal. Closes issue #275.
Diffstat (limited to 'checkers')
-rw-r--r-- | checkers/variables.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index 29f9529..4150706 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -422,8 +422,11 @@ builtins. Remember that you should avoid to define new builtins when possible.' called_overridden = False argnames = node.argnames() global_names = set() + nonlocal_names = set() for global_stmt in node.nodes_of_class(astroid.Global): global_names.update(set(global_stmt.names)) + for nonlocal_stmt in node.nodes_of_class(astroid.Nonlocal): + nonlocal_names.update(set(nonlocal_stmt.names)) for name, stmts in not_consumed.iteritems(): # ignore some special names specified by user configuration @@ -470,6 +473,9 @@ builtins. Remember that you should avoid to define new builtins when possible.' continue self.add_message('unused-argument', args=name, node=stmt) else: + if stmt.parent and isinstance(stmt.parent, astroid.Assign): + if name in nonlocal_names: + continue self.add_message('unused-variable', args=name, node=stmt) @check_messages('global-variable-undefined', 'global-variable-not-assigned', 'global-statement', |