Skip to content

Commit b9ecb4d

Browse files
DanielNoordPierre-Sassoulas
authored andcommitted
Fix false positive for useless-super-delegation for variadics (#6949)
1 parent f881219 commit b9ecb4d

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

doc/whatsnew/2/2.14/full.rst

+3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ What's New in Pylint 2.14.3?
55
----------------------------
66
Release date: TBA
77

8+
* Fixed a false positive for ``useless-super-delegation`` for subclasses that specify the number of
9+
of parameters against a parent that uses a variadic argument.
810

11+
Closes #2270
912

1013
What's New in Pylint 2.14.2?
1114
----------------------------

pylint/checkers/classes/class_checker.py

+6
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,12 @@ def _check_useless_super_delegation(self, function: nodes.FunctionDef) -> None:
12761276
args = _signature_from_call(call)
12771277

12781278
if meth_node is not None:
1279+
# Detect if the super method uses varargs and the function doesn't or makes some of those explicit
1280+
if meth_node.args.vararg and (
1281+
not function.args.vararg
1282+
or len(function.args.args) > len(meth_node.args.args)
1283+
):
1284+
return
12791285

12801286
def form_annotations(arguments):
12811287
annotations = chain(

tests/functional/u/useless/useless_super_delegation.py

+31
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,34 @@ def __str__(self):
303303

304304
def __hash__(self): # [useless-super-delegation]
305305
return super().__hash__()
306+
307+
308+
# Reported in https://github.com/PyCQA/pylint/issues/2270
309+
class Super:
310+
def __init__(self, *args):
311+
self.args = args
312+
313+
314+
class Sub(Super):
315+
def __init__(self, a, b):
316+
super().__init__(a, b)
317+
318+
319+
class SubTwo(Super):
320+
def __init__(self, a, *args):
321+
super().__init__(a, *args)
322+
323+
324+
class SuperTwo:
325+
def __init__(self, a, *args):
326+
self.args = args
327+
328+
329+
class SubTwoOne(SuperTwo):
330+
def __init__(self, a, *args): # [useless-super-delegation]
331+
super().__init__(a, *args)
332+
333+
334+
class SubTwoTwo(SuperTwo):
335+
def __init__(self, a, b, *args):
336+
super().__init__(a, b, *args)

tests/functional/u/useless/useless_super_delegation.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ useless-super-delegation:264:4:264:28:UselessSuper.with_default_arg_bis:Useless
1818
useless-super-delegation:267:4:267:28:UselessSuper.with_default_arg_ter:Useless super delegation in method 'with_default_arg_ter':UNDEFINED
1919
useless-super-delegation:270:4:270:29:UselessSuper.with_default_arg_quad:Useless super delegation in method 'with_default_arg_quad':UNDEFINED
2020
useless-super-delegation:304:4:304:16:DecoratedList.__hash__:Useless super delegation in method '__hash__':UNDEFINED
21+
useless-super-delegation:330:4:330:16:SubTwoOne.__init__:Useless super delegation in method '__init__':UNDEFINED

0 commit comments

Comments
 (0)