summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Marek <tmarek@google.com>2013-06-18 10:00:54 +0200
committerTorsten Marek <tmarek@google.com>2013-06-18 10:00:54 +0200
commitf6b5fc84a2ff8935e1f2d1f0304d7290adb8c6af (patch)
tree5c8776c8fbf212d41ed5b707b5353c29bb2a116a
parente7670dfa2173b5b8a3d99fd3d4f26f7e9e4fbc41 (diff)
downloadpylint-f6b5fc84a2ff8935e1f2d1f0304d7290adb8c6af.tar.gz
Do not warn about redefinitions of dummy variables.
-rw-r--r--ChangeLog2
-rw-r--r--checkers/variables.py4
-rw-r--r--test/input/func_no_dummy_redefined.py14
-rw-r--r--test/messages/func_no_dummy_redefined.txt2
4 files changed, 21 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 01f9971..ee0e6e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@ ChangeLog for Pylint
====================
--
+ * Do not warn about redefinitions of variables that match the
+ dummy regex.
* Do not treat all variables starting with _ as dummy variables,
only _ itself.
* Make the line-too-long warning configurable by
diff --git a/checkers/variables.py b/checkers/variables.py
index b50ba08..3c93d17 100644
--- a/checkers/variables.py
+++ b/checkers/variables.py
@@ -273,7 +273,9 @@ builtins. Remember that you should avoid to define new builtins when possible.'
continue
if name in globs and not isinstance(stmt, astroid.Global):
line = globs[name][0].fromlineno
- self.add_message('W0621', args=(name, line), node=stmt)
+ dummy_rgx = self.config.dummy_variables_rgx
+ if not dummy_rgx.match(name):
+ self.add_message('W0621', args=(name, line), node=stmt)
elif is_builtin(name):
# do not print Redefining builtin for additional builtins
self.add_message('W0622', args=name, node=stmt)
diff --git a/test/input/func_no_dummy_redefined.py b/test/input/func_no_dummy_redefined.py
new file mode 100644
index 0000000..8af89d8
--- /dev/null
+++ b/test/input/func_no_dummy_redefined.py
@@ -0,0 +1,14 @@
+"""Make sure warnings about redefinitions do not trigger for dummy variables."""
+__revision__ = 0
+
+
+_, INTERESTING = 'a=b'.split('=')
+
+value = 10
+
+
+def clobbering():
+ """Clobbers a dummy name from the outer scope."""
+ value = 9
+ for _ in range(7):
+ print value
diff --git a/test/messages/func_no_dummy_redefined.txt b/test/messages/func_no_dummy_redefined.txt
new file mode 100644
index 0000000..f207712
--- /dev/null
+++ b/test/messages/func_no_dummy_redefined.txt
@@ -0,0 +1,2 @@
+C: 7: Invalid name "value" for type constant (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
+W: 12:clobbering: Redefining name 'value' from outer scope (line 7)