diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index bb3f3d169d..eb786d0f8d 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -1298,6 +1298,14 @@ def form_annotations(arguments): if called_annotations != overridden_annotations: return + if ( + function.returns is not None and + meth_node.returns is None + or meth_node.returns.as_string() != function.returns.as_string() + ): + # Override adds typing information to the return type + return + if _definition_equivalent_to_call(params, args): self.add_message( "useless-super-delegation", node=function, args=(function.name,) diff --git a/tests/functional/u/useless/useless_super_delegation_py35.py b/tests/functional/u/useless/useless_super_delegation_py35.py index 16030f8a4d..93a77f5011 100644 --- a/tests/functional/u/useless/useless_super_delegation_py35.py +++ b/tests/functional/u/useless/useless_super_delegation_py35.py @@ -10,3 +10,37 @@ class UselessSuper(object): def useless(self, first, *, second=None, **kwargs): # [useless-super-delegation] return super().useless(first, second=second, **kwargs) + +# pylint: disable=wrong-import-position +import random +from typing import Any + +class ReturnTypeAny: + choices = ['a', 1, (2, 3)] + + def draw(self) -> Any: + return random.choice(self.choices) + +class ReturnTypeNarrowed(ReturnTypeAny): + choices = [1, 2, 3] + + def draw(self) -> int: + return super().draw() + +class NoReturnType: + choices = ['a', 1, (2, 3)] + + def draw(self): + return random.choice(self.choices) + +class ReturnTypeSpecified(NoReturnType): + choices = ['a', 'b'] + + def draw(self) -> str: + return super().draw() + +class ReturnTypeSame(ReturnTypeAny): + choices = ['a', 'b'] + + def draw(self) -> Any: # [useless-super-delegation] + return super().draw() diff --git a/tests/functional/u/useless/useless_super_delegation_py35.txt b/tests/functional/u/useless/useless_super_delegation_py35.txt index abcf6c5fb4..9fcf254471 100644 --- a/tests/functional/u/useless/useless_super_delegation_py35.txt +++ b/tests/functional/u/useless/useless_super_delegation_py35.txt @@ -1 +1,2 @@ useless-super-delegation:11:4:11:15:UselessSuper.useless:Useless super delegation in method 'useless':UNDEFINED +useless-super-delegation:45:4:45:12:ReturnTypeSame.draw:Useless super delegation in method 'draw':UNDEFINED