summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Pribysh <dmand@yandex.ru>2015-10-17 16:50:06 +0300
committerDmitry Pribysh <dmand@yandex.ru>2015-10-17 16:50:06 +0300
commite19536a645f93b7a02173c4166b928c185a02aa4 (patch)
tree2f3d7b48785fa085487dc4bf5a8dbdb6eeb8ce39
parent4b887f72eb67cc6f3324c396c826008e34476959 (diff)
downloadpylint-e19536a645f93b7a02173c4166b928c185a02aa4.tar.gz
Make `no-self-use` checker not throw a warning if method has a `super()` call.
This is only enabled for python 3.0+ and only for `super` calls with no arguments. Fixes issue #667.
-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
4 files changed, 25 insertions, 1 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index 0fc0fae..c628e94 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_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_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 @@
+