Skip to content

Commit

Permalink
don't add 'useless-super-delegation' if annotations are different (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Green committed May 15, 2018
1 parent c011c53 commit 19a0d09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pylint/checkers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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, ))
Expand Down
13 changes: 13 additions & 0 deletions pylint/test/functional/useless_super_delegation_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions pylint/test/functional/useless_super_delegation_py3.txt
Original file line number Diff line number Diff line change
@@ -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__'

0 comments on commit 19a0d09

Please sign in to comment.