Skip to content

Fix a false negative for too-many-arguments and positional-only and keyword-only arguments #8674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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/8667.false_negative
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a false negative for ``too-many-arguments`` by considering positional-only and keyword-only parameters.

Closes #8667
2 changes: 1 addition & 1 deletion pylint/checkers/design_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
# init branch and returns counters
self._returns.append(0)
# check number of arguments
args = node.args.args
args = node.args.args + node.args.posonlyargs + node.args.kwonlyargs
ignored_argument_names = self.linter.config.ignored_argument_names
if args is not None:
ignored_args_num = 0
Expand Down
5 changes: 5 additions & 0 deletions pylint/config/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class _StoreArgument(_BaseStoreArgument):
https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
"""

# pylint: disable-next=too-many-arguments
def __init__(
self,
*,
Expand Down Expand Up @@ -306,6 +307,7 @@ class _DeprecationArgument(_Argument):
https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
"""

# pylint: disable-next=too-many-arguments
def __init__(
self,
*,
Expand Down Expand Up @@ -354,6 +356,7 @@ class _ExtendArgument(_DeprecationArgument):
https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
"""

# pylint: disable-next=too-many-arguments
def __init__(
self,
*,
Expand Down Expand Up @@ -398,6 +401,7 @@ class _StoreOldNamesArgument(_DeprecationArgument):
https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
"""

# pylint: disable-next=too-many-arguments
def __init__(
self,
*,
Expand Down Expand Up @@ -435,6 +439,7 @@ class _StoreNewNamesArgument(_DeprecationArgument):
https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
"""

# pylint: disable-next=too-many-arguments
def __init__(
self,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This test is 3.8+ as the columns are not correctly identified
by the ast parser < 3.8
"""
# pylint: disable=unused-argument
# pylint: disable=unused-argument,too-many-arguments


def name(
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/t/too/too_many_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ def func_call():
partial_func = partial(root_function, 1, 2, 3)
partial_func()
return root_function(1, 2, 3)


# +1: [too-many-arguments]
def name1(param1, param2, param3, /, param4, param5, *args, param6="apple", **kwargs):
return param1, param2, param3, param4, param5, param6, args, kwargs
1 change: 1 addition & 0 deletions tests/functional/t/too/too_many_arguments.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
too-many-arguments:3:0:3:19:stupid_function:Too many arguments (9/5):UNDEFINED
too-many-arguments:36:0:36:9:name1:Too many arguments (6/5):UNDEFINED