summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-06-15 13:37:05 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-06-18 10:31:21 +0200
commitb9ecb4d70d23f7a6d05cc14e94c26fd8d3261d0f (patch)
tree4710453859f8daeb00be046c620f09783171279b
parentf881219a66deaf9cef6467ba27c3385bc98dad82 (diff)
downloadpylint-git-b9ecb4d70d23f7a6d05cc14e94c26fd8d3261d0f.tar.gz
Fix false positive for ``useless-super-delegation`` for variadics (#6949)
-rw-r--r--doc/whatsnew/2/2.14/full.rst3
-rw-r--r--pylint/checkers/classes/class_checker.py6
-rw-r--r--tests/functional/u/useless/useless_super_delegation.py31
-rw-r--r--tests/functional/u/useless/useless_super_delegation.txt1
4 files changed, 41 insertions, 0 deletions
diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst
index 758470c59..608664cbb 100644
--- a/doc/whatsnew/2/2.14/full.rst
+++ b/doc/whatsnew/2/2.14/full.rst
@@ -5,7 +5,10 @@ What's New in Pylint 2.14.3?
----------------------------
Release date: TBA
+* Fixed a false positive for ``useless-super-delegation`` for subclasses that specify the number of
+ of parameters against a parent that uses a variadic argument.
+ Closes #2270
What's New in Pylint 2.14.2?
----------------------------
diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py
index 8ecce86cb..933e65c6c 100644
--- a/pylint/checkers/classes/class_checker.py
+++ b/pylint/checkers/classes/class_checker.py
@@ -1276,6 +1276,12 @@ a metaclass class method.",
args = _signature_from_call(call)
if meth_node is not None:
+ # Detect if the super method uses varargs and the function doesn't or makes some of those explicit
+ if meth_node.args.vararg and (
+ not function.args.vararg
+ or len(function.args.args) > len(meth_node.args.args)
+ ):
+ return
def form_annotations(arguments):
annotations = chain(
diff --git a/tests/functional/u/useless/useless_super_delegation.py b/tests/functional/u/useless/useless_super_delegation.py
index 2a7ecb787..cc7d51b65 100644
--- a/tests/functional/u/useless/useless_super_delegation.py
+++ b/tests/functional/u/useless/useless_super_delegation.py
@@ -303,3 +303,34 @@ class DecoratedList(MyList):
def __hash__(self): # [useless-super-delegation]
return super().__hash__()
+
+
+# Reported in https://github.com/PyCQA/pylint/issues/2270
+class Super:
+ def __init__(self, *args):
+ self.args = args
+
+
+class Sub(Super):
+ def __init__(self, a, b):
+ super().__init__(a, b)
+
+
+class SubTwo(Super):
+ def __init__(self, a, *args):
+ super().__init__(a, *args)
+
+
+class SuperTwo:
+ def __init__(self, a, *args):
+ self.args = args
+
+
+class SubTwoOne(SuperTwo):
+ def __init__(self, a, *args): # [useless-super-delegation]
+ super().__init__(a, *args)
+
+
+class SubTwoTwo(SuperTwo):
+ def __init__(self, a, b, *args):
+ super().__init__(a, b, *args)
diff --git a/tests/functional/u/useless/useless_super_delegation.txt b/tests/functional/u/useless/useless_super_delegation.txt
index 8184524af..9cf311573 100644
--- a/tests/functional/u/useless/useless_super_delegation.txt
+++ b/tests/functional/u/useless/useless_super_delegation.txt
@@ -18,3 +18,4 @@ useless-super-delegation:264:4:264:28:UselessSuper.with_default_arg_bis:Useless
useless-super-delegation:267:4:267:28:UselessSuper.with_default_arg_ter:Useless super delegation in method 'with_default_arg_ter':UNDEFINED
useless-super-delegation:270:4:270:29:UselessSuper.with_default_arg_quad:Useless super delegation in method 'with_default_arg_quad':UNDEFINED
useless-super-delegation:304:4:304:16:DecoratedList.__hash__:Useless super delegation in method '__hash__':UNDEFINED
+useless-super-delegation:330:4:330:16:SubTwoOne.__init__:Useless super delegation in method '__init__':UNDEFINED