diff --git a/doc/whatsnew/fragments/9036.false_positive b/doc/whatsnew/fragments/9036.false_positive new file mode 100644 index 0000000000..91deaa2d4b --- /dev/null +++ b/doc/whatsnew/fragments/9036.false_positive @@ -0,0 +1,3 @@ +Fix a false positive for ``no-value-for-parameter`` when a staticmethod is called in a class body. + +Closes #9036 diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index ede366fd3f..72ebd74036 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -1504,10 +1504,10 @@ def visit_call(self, node: nodes.Call) -> None: # includes an implicit `self` argument which is not present in `called.args`. if ( isinstance(node.frame(), nodes.ClassDef) - and isinstance(node.parent, (nodes.Assign, nodes.AnnAssign)) and isinstance(called, nodes.FunctionDef) and called in node.frame().body and num_positional_args > 0 + and "builtins.staticmethod" not in called.decoratornames() ): num_positional_args -= 1 diff --git a/tests/functional/a/arguments.py b/tests/functional/a/arguments.py index 81a9bb73d9..a312c45e6a 100644 --- a/tests/functional/a/arguments.py +++ b/tests/functional/a/arguments.py @@ -320,3 +320,14 @@ def name6(param1, **kwargs): ... name4(1, param2=False) name5() name6(param1=43) + + +# https://github.com/pylint-dev/pylint/issues/9036 +# No value for argument 'string' in staticmethod call (no-value-for-parameter) +class Foo: + @staticmethod + def func(string): + return string + + func(42) + a = func(42)