summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-10-18 17:44:43 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2015-10-18 17:44:43 +0300
commita80c61921d59b919be50612f2fa9139d4e24244a (patch)
treece900cde918a3a3725e3e50acfef36963e80585c
parentbd5a11987fc9d9145a1414db635c803818ddd5c9 (diff)
parent3df1fb9ee598eec589c988b7790cf44b031341f2 (diff)
downloadpylint-a80c61921d59b919be50612f2fa9139d4e24244a.tar.gz
Merged in dmand/pylint/fix-667 (pull request #287)
Make `no-self-use` checker not throw a warning if method has a `super()` call.
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/classes.py11
-rw-r--r--pylint/test/functional/no_self_use_py3.py12
-rw-r--r--pylint/test/functional/no_self_use_py3.rc2
-rw-r--r--pylint/test/functional/no_self_use_py3.txt1
5 files changed, 29 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 964ab1a..1036a31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@ ChangeLog for Pylint
--------------------
--
+ * Make 'no-self-use' checker not emit a warning if there is a 'super()'
+ call inside the method.
+ Closes issue #667.
+
* Add checker to identify multiple imports on one line.
Closes issue #598.
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index 0fc0fae..c39b971 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -140,6 +140,14 @@ def _is_attribute_property(name, klass):
return True
return False
+def _has_bare_super_call(fundef_node):
+ for call in fundef_node.nodes_of_class(astroid.Call):
+ func = call.func
+ if (isinstance(func, astroid.Name) and
+ func.name == 'super' and
+ not call.args):
+ return True
+ return False
MSGS = {
'F0202': ('Unable to check methods signature (%s / %s)',
@@ -545,7 +553,8 @@ a metaclass class method.'}
and not node.name in PYMETHODS
and not (node.is_abstract() or
overrides_a_method(class_node, node.name) or
- decorated_with_property(node))):
+ decorated_with_property(node) or
+ (six.PY3 and _has_bare_super_call(node)))):
self.add_message('no-self-use', node=node)
def visit_attribute(self, node):
diff --git a/pylint/test/functional/no_self_use_py3.py b/pylint/test/functional/no_self_use_py3.py
new file mode 100644
index 0000000..f401508
--- /dev/null
+++ b/pylint/test/functional/no_self_use_py3.py
@@ -0,0 +1,12 @@
+# pylint: disable=missing-docstring,no-init,unused-argument,invalid-name,too-few-public-methods
+
+class A:
+ def __init__(self):
+ self.store = {}
+
+ def get(self, key, default=None):
+ return self.store.get(key, default)
+
+class B(A):
+ def get_memo(self, obj):
+ return super().get(obj)
diff --git a/pylint/test/functional/no_self_use_py3.rc b/pylint/test/functional/no_self_use_py3.rc
new file mode 100644
index 0000000..a2ab06c
--- /dev/null
+++ b/pylint/test/functional/no_self_use_py3.rc
@@ -0,0 +1,2 @@
+[testoptions]
+min_pyver=3.0 \ No newline at end of file
diff --git a/pylint/test/functional/no_self_use_py3.txt b/pylint/test/functional/no_self_use_py3.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/pylint/test/functional/no_self_use_py3.txt
@@ -0,0 +1 @@
+