summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Marek <tmarek@google.com>2013-03-29 17:45:04 +0100
committerTorsten Marek <tmarek@google.com>2013-03-29 17:45:04 +0100
commitb7672dfd8626555a1c99a4ea4da0d7c585aa3b3a (patch)
tree4a18fe954dba3c6961c96a760b462564fe314a22
parent7898988fb528b0c48e08abbb35a95603861e51ce (diff)
downloadpylint-b7672dfd8626555a1c99a4ea4da0d7c585aa3b3a.tar.gz
Unify handling for dangerous default values and make sure that set, dict and list literals
are treated the same way as list(), set() and dict(). Depends on inference fixes found in logilab-astng 0.24.3/0.25
-rw-r--r--ChangeLog3
-rw-r--r--__pkginfo__.py2
-rw-r--r--checkers/base.py11
-rw-r--r--debian/control2
-rw-r--r--test/input/func_dangerous_default.py11
-rw-r--r--test/messages/func_dangerous_default.txt5
6 files changed, 24 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index bb44729..bc269c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,9 @@ ChangeLog for PyLint
* #124662: fix name error causing crash when symbols are included in output
messages
+ * Simplify checks for dangerous default values by unifying tests
+ for all different mutable compound literals.
+
2013-02-26 -- 0.27.0
* #20693: replace pylint.el by Ian Eure version (patch by J.Kotta)
diff --git a/__pkginfo__.py b/__pkginfo__.py
index 5604692..542ad0d 100644
--- a/__pkginfo__.py
+++ b/__pkginfo__.py
@@ -21,7 +21,7 @@ modname = distname = 'pylint'
numversion = (0, 27, 0)
version = '.'.join([str(num) for num in numversion])
-install_requires = ['logilab-common >= 0.53.0', 'logilab-astng >= 0.21.1']
+install_requires = ['logilab-common >= 0.53.0', 'logilab-astng >= 0.24.3']
license = 'GPL'
copyright = 'Logilab S.A.'
diff --git a/checkers/base.py b/checkers/base.py
index 41e4b93..1fab58b 100644
--- a/checkers/base.py
+++ b/checkers/base.py
@@ -448,18 +448,15 @@ functions, methods
value = default.infer().next()
except astng.InferenceError:
continue
- if isinstance(value, (astng.Dict, astng.List)):
+ if (isinstance(value, astng.Instance) and
+ value.qname() in ('__builtin__.set', '__builtin__.dict', '__builtin__.list')):
if value is default:
msg = default.as_string()
+ elif type(value) is astng.Instance:
+ msg = '%s (%s)' % (default.as_string(), value.qname())
else:
msg = '%s (%s)' % (default.as_string(), value.as_string())
self.add_message('W0102', node=node, args=(msg,))
- if value.qname() == '__builtin__.set':
- if isinstance(default, astng.CallFunc):
- msg = default.as_string()
- else:
- msg = '%s (%s)' % (default.as_string(), value.qname())
- self.add_message('W0102', node=node, args=(msg,))
@check_messages('W0101', 'W0150')
def visit_return(self, node):
diff --git a/debian/control b/debian/control
index 33d2056..b96f9f1 100644
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,7 @@ Vcs-Browser: http://svn.debian.org/viewsvn/python-apps/packages/pylint/trunk/
Package: pylint
Architecture: all
-Depends: ${python:Depends}, ${misc:Depends}, python-logilab-common (>= 0.53.0), python-logilab-astng (>= 0.21.1)
+Depends: ${python:Depends}, ${misc:Depends}, python-logilab-common (>= 0.53.0), python-logilab-astng (>= 0.24.3)
Suggests: python-tk
XB-Python-Version: ${python:Versions}
Conflicts: python2.2-pylint, python2.3-pylint, python2.4-pylint, pylint-common, pylint-test
diff --git a/test/input/func_dangerous_default.py b/test/input/func_dangerous_default.py
index 8a526e2..a6b1a05 100644
--- a/test/input/func_dangerous_default.py
+++ b/test/input/func_dangerous_default.py
@@ -30,3 +30,14 @@ def function6(value = GLOBAL_SET):
"""set is mutable and dangerous."""
print value
+def function7(value = dict()):
+ """dict is mutable and dangerous."""
+ print value
+
+def function8(value = {1}):
+ """set is mutable and dangerous."""
+ print value
+
+def function9(value = list()):
+ """list is mutable and dangerous."""
+ print value
diff --git a/test/messages/func_dangerous_default.txt b/test/messages/func_dangerous_default.txt
index b882844..179a4c5 100644
--- a/test/messages/func_dangerous_default.txt
+++ b/test/messages/func_dangerous_default.txt
@@ -1,4 +1,7 @@
W: 7:function1: Dangerous default value [] as argument
W: 11:function2: Dangerous default value HEHE ({}) as argument
-W: 19:function4: Dangerous default value set() as argument
+W: 19:function4: Dangerous default value set() (__builtin__.set) as argument
W: 29:function6: Dangerous default value GLOBAL_SET (__builtin__.set) as argument
+W: 33:function7: Dangerous default value dict() (__builtin__.dict) as argument
+W: 37:function8: Dangerous default value {1} as argument
+W: 41:function9: Dangerous default value list() (__builtin__.list) as argument