summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsylvain thenault <sylvain.thenault@logilab.fr>2009-01-16 10:01:40 +0100
committersylvain thenault <sylvain.thenault@logilab.fr>2009-01-16 10:01:40 +0100
commit45694b2338d18291cb3d1931cd0434cab8aa65e6 (patch)
treef80656c286ed8c7bdc2a64c9238d812ecdf5293c
parent20ebed73995b005f45fffa2bd8565ea086ad11a7 (diff)
downloadpylint-45694b2338d18291cb3d1931cd0434cab8aa65e6.tar.gz
fix #6949: as suggested by m. kiilerich, we should remove __dict__ node added by astng to avoid E0601/E0602 false negative
-rw-r--r--checkers/variables.py9
-rw-r--r--test/input/func_module___dict__.py9
-rw-r--r--test/messages/func_module___dict__.txt1
3 files changed, 18 insertions, 1 deletions
diff --git a/checkers/variables.py b/checkers/variables.py
index dab949c..a3b1501 100644
--- a/checkers/variables.py
+++ b/checkers/variables.py
@@ -132,7 +132,14 @@ builtins. Remember that you should avoid to define new builtins when possible.'
"""visit module : update consumption analysis variable
checks globals doesn't overrides builtins
"""
- self._to_consume = [(copy(node.locals), {}, 'module')]
+ mlocals = copy(node.locals)
+ # __dict__ is added to module's locals but not available in module's namespace
+ # (unlike __doc__, __name__, etc...). But take care __dict__ may be assigned
+ # somewhere in the module, so remove astng inserted nodes (having None lineno)
+ mlocals['__dict__'] = [n for n in mlocals['__dict__'] if n.lineno is not None]
+ if not mlocals['__dict__']:
+ del mlocals['__dict__']
+ self._to_consume = [(mlocals, {}, 'module')]
self._vars = []
for name, stmts in node.locals.items():
if name in ('__name__', '__doc__', '__file__', '__path__') \
diff --git a/test/input/func_module___dict__.py b/test/input/func_module___dict__.py
new file mode 100644
index 0000000..0cf1550
--- /dev/null
+++ b/test/input/func_module___dict__.py
@@ -0,0 +1,9 @@
+"""http://www.logilab.org/ticket/6949."""
+
+__revision__ = None
+
+print __dict__ is not None
+
+__dict__ = {}
+
+print __dict__ is not None
diff --git a/test/messages/func_module___dict__.txt b/test/messages/func_module___dict__.txt
new file mode 100644
index 0000000..4169824
--- /dev/null
+++ b/test/messages/func_module___dict__.txt
@@ -0,0 +1 @@
+E: 5: Using variable '__dict__' before assignment