Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9036.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a false positive for ``no-value-for-parameter`` when a staticmethod is called in a class body.

Closes #9036
2 changes: 1 addition & 1 deletion pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Member Author

@mbyrnepr2 mbyrnepr2 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if block was added by me originally. I don't think there was any need to specify that this node was an assignment; i.e. this should be checked also:

class X:
    def func(xx):
        ...
    func("test")

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

Expand Down
11 changes: 11 additions & 0 deletions tests/functional/a/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)