Skip to content

Commit

Permalink
Suppress useless-super-delegation if return type changed (pylint-…
Browse files Browse the repository at this point in the history
  • Loading branch information
timmartin committed Apr 2, 2022
1 parent aaeeb33 commit 672bf9a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,13 @@ def _check_useless_super_delegation(self, function):

if meth_node is not None:

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

def form_annotations(arguments):
annotations = chain(
(arguments.posonlyargs_annotations or []), arguments.annotations
Expand Down
27 changes: 27 additions & 0 deletions tests/functional/u/useless/useless_super_delegation_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,30 @@ def __init__(self, thing: object) -> None: # [useless-super-delegation]
class Test:
def __init__(self, _arg: List[int]) -> None:
super().__init__()


import random

class ReturnTypeAny:
choices = ['a', 1, (2, 3)]

def draw(self) -> None:
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()

0 comments on commit 672bf9a

Please sign in to comment.