summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Green <benhgreen@icloud.com>2018-05-15 13:11:24 -0400
committerClaudiu Popa <pcmanticore@gmail.com>2018-05-15 13:11:24 -0400
commit64c4d9c006a9b03414d4ac34e17aeffd3f8903cd (patch)
treead71734d120a3868b8f77adfa10d4b34fae3b1c1
parent7297c643dc6dee228885234e7bdff6186e3c6bc1 (diff)
downloadpylint-git-64c4d9c006a9b03414d4ac34e17aeffd3f8903cd.tar.gz
Don't emit 'useless-super-delegation' if annotations are different
Fixes #1923
-rw-r--r--ChangeLog4
-rw-r--r--doc/whatsnew/2.0.rst2
-rw-r--r--pylint/checkers/classes.py11
-rw-r--r--pylint/test/functional/useless_super_delegation_py3.py13
-rw-r--r--pylint/test/functional/useless_super_delegation_py3.txt1
5 files changed, 31 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 833d87739..577f1488f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,10 @@ Pylint's ChangeLog
What's New in Pylint 2.0?
=========================
+ * Don't show 'useless-super-delegation' if the subclass method has different type annotations.
+
+ Close #1923
+
* Add `unhashable-dict-key` check.
Closes #586
diff --git a/doc/whatsnew/2.0.rst b/doc/whatsnew/2.0.rst
index cfa74e55d..b4cf46cdb 100644
--- a/doc/whatsnew/2.0.rst
+++ b/doc/whatsnew/2.0.rst
@@ -166,6 +166,8 @@ Other Changes
* Skip wildcard import check for `__init__.py`.
+* Don't warn 'useless-super-delegation' if the subclass method has different type annotations.
+
* Don't warn that a global variable is unused if it is defined by an import
.. code-block:: python
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index 079b4ef02..75416c49d 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -842,6 +842,7 @@ a metaclass class method.'}
# Check values of default args
klass = function.parent.frame()
+ meth_node = None
for overridden in klass.local_attr_ancestors(function.name):
# get astroid for the searched method
try:
@@ -862,6 +863,16 @@ a metaclass class method.'}
# Detect if the parameters are the same as the call's arguments.
params = _signature_from_arguments(function.args)
args = _signature_from_call(call)
+
+ if meth_node is not None:
+ def form_annotations(annotations):
+ return [a.name if a is not None else a for a in annotations]
+ called_annotations = form_annotations(function.args.annotations)
+ overridden_annotations = form_annotations(meth_node.args.annotations)
+ if called_annotations and overridden_annotations:
+ if called_annotations != overridden_annotations:
+ return
+
if _definition_equivalent_to_call(params, args):
self.add_message('useless-super-delegation', node=function,
args=(function.name, ))
diff --git a/pylint/test/functional/useless_super_delegation_py3.py b/pylint/test/functional/useless_super_delegation_py3.py
index 7060760e0..4cd63a574 100644
--- a/pylint/test/functional/useless_super_delegation_py3.py
+++ b/pylint/test/functional/useless_super_delegation_py3.py
@@ -14,3 +14,16 @@ class UselessSuper(object):
def useless(self, *, first): # [useless-super-delegation]
super(UselessSuper, self).useless(first=first)
+
+
+class Egg():
+ def __init__(self, thing: object) -> None:
+ pass
+
+class Spam(Egg):
+ def __init__(self, thing: int) -> None:
+ super().__init__(thing)
+
+class Ham(Egg):
+ def __init__(self, thing: object) -> None: # [useless-super-delegation]
+ super().__init__(thing)
diff --git a/pylint/test/functional/useless_super_delegation_py3.txt b/pylint/test/functional/useless_super_delegation_py3.txt
index 3c7e570df..ee5a97df2 100644
--- a/pylint/test/functional/useless_super_delegation_py3.txt
+++ b/pylint/test/functional/useless_super_delegation_py3.txt
@@ -1 +1,2 @@
useless-super-delegation:15:UselessSuper.useless:Useless super delegation in method 'useless'
+useless-super-delegation:28:Ham.__init__:Useless super delegation in method '__init__'