diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index 079b4ef02e..75416c49d6 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -842,6 +842,7 @@ def _check_useless_super_delegation(self, function): # 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 @@ def _check_useless_super_delegation(self, function): # 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 7060760e02..4cd63a574a 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 3c7e570dfb..ee5a97df2f 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__'