summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmarek <tmarek@google.com>2013-01-08 19:30:22 +0100
committertmarek <tmarek@google.com>2013-01-08 19:30:22 +0100
commit8111a29f0b606367b02704e65678818977ac9cb0 (patch)
tree6f5ecf358b47f6d36281b240592ee5f0ea0a7e1e
parent72f76bb389d07ceeace16174781f7afa3e90104c (diff)
downloadpylint-8111a29f0b606367b02704e65678818977ac9cb0.tar.gz
Emit a warning if __all__ contains non-string objects.
Closes #112728
-rw-r--r--ChangeLog19
-rw-r--r--checkers/variables.py6
-rw-r--r--test/input/func_e0604.py13
-rw-r--r--test/input/func_more_e0604.py9
-rw-r--r--test/messages/func_e0604.txt1
-rw-r--r--test/messages/func_more_e0604.txt1
6 files changed, 40 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index a57fb47..f8b06e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,15 @@ ChangeLog for PyLint
--
+ * Changed the regular expression for inline options so that it must be
+ preceeded by a # (patch by Torsten Marek)
+
+ * Make dot output for import graph predictable and not depend
+ on ordering of strings in hashes. (patch by Torsten Marek)
+
+ * Add hooks for import path setup and move pylint's sys.path
+ modifications into them. (patch by Torsten Marek)
+
* #20693: replace pylint.el by Ian Eure version (patch by J.Kotta)
* #105327: add support for --disable=all option and deprecate the
@@ -12,14 +21,8 @@ ChangeLog for PyLint
* #110840: Add messages I0020 and I0021 for reporting of suppressed messages
and useless suppression pragmas. (patch by Torsten Marek)
- * Changed the regular expression for inline options so that it must be
- preceeded by a # (patch by Torsten Marek)
-
- * Make dot output for import graph predictable and not depend
- on ordering of strings in hashes. (patch by Torsten Marek)
-
- * Add hooks for import path setup and move pylint's sys.path
- modifications into them. (patch by Torsten Marek)
+ * #112728: Add warning E0604 for non-string objects in __all__
+ (patch by Torsten Marek)
--
* #115580: fix erroneous W0212 (access to protected member) on super call
diff --git a/checkers/variables.py b/checkers/variables.py
index d094e6c..cf5d9f7 100644
--- a/checkers/variables.py
+++ b/checkers/variables.py
@@ -63,6 +63,9 @@ MSGS = {
'E0603': ('Undefined variable name %r in __all__',
'undefined-all-variable',
'Used when an undefined variable name is referenced in __all__.'),
+ 'E0604': ('Invalid object %r in __all__, must contain only strings',
+ 'invalid-all-object',
+ 'Used when an invalid (non-string) object occurs in __all__.'),
'E0611': ('No name %r in module %r',
'no-name-in-module',
'Used when a name cannot be found in a module.'),
@@ -179,7 +182,8 @@ builtins. Remember that you should avoid to define new builtins when possible.'
except astng.InferenceError:
continue
- if not isinstance(elt_name, astng.Const):
+ if not isinstance(elt_name, astng.Const) or not isinstance(elt_name.value, basestring):
+ self.add_message('E0604', args=elt.as_string(), node=elt)
continue
elt_name = elt.value
# If elt is in not_consumed, remove it from not_consumed
diff --git a/test/input/func_e0604.py b/test/input/func_e0604.py
new file mode 100644
index 0000000..d077f31
--- /dev/null
+++ b/test/input/func_e0604.py
@@ -0,0 +1,13 @@
+"""Test for invalid objects in a module's __all__ variable.
+
+"""
+# pylint: disable=R0903,R0201,W0612
+
+__revision__ = 0
+
+def some_function():
+ """Just a function."""
+ pass
+
+
+__all__ = [some_function]
diff --git a/test/input/func_more_e0604.py b/test/input/func_more_e0604.py
new file mode 100644
index 0000000..6c39e1c
--- /dev/null
+++ b/test/input/func_more_e0604.py
@@ -0,0 +1,9 @@
+"""Test for invalid objects in a module's __all__ variable.
+
+"""
+# pylint: disable=R0903,R0201,W0612
+
+__revision__ = 0
+
+
+__all__ = [1]
diff --git a/test/messages/func_e0604.txt b/test/messages/func_e0604.txt
new file mode 100644
index 0000000..e232633
--- /dev/null
+++ b/test/messages/func_e0604.txt
@@ -0,0 +1 @@
+E: 13: Invalid object 'some_function' in __all__, must contain only strings
diff --git a/test/messages/func_more_e0604.txt b/test/messages/func_more_e0604.txt
new file mode 100644
index 0000000..080c59f
--- /dev/null
+++ b/test/messages/func_more_e0604.txt
@@ -0,0 +1 @@
+E: 9: Invalid object '1' in __all__, must contain only strings