From 0a6c21bfab8237431c9f5198068451b243e91448 Mon Sep 17 00:00:00 2001 From: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Date: Mon, 15 May 2023 20:51:58 +0200 Subject: Fix a false negative for ``too-many-arguments`` and positional-only and keyword-only arguments (#8674) Closes #8667 --- doc/whatsnew/fragments/8667.false_negative | 3 +++ pylint/checkers/design_analysis.py | 2 +- pylint/config/argument.py | 5 +++++ .../n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py | 2 +- tests/functional/t/too/too_many_arguments.py | 5 +++++ tests/functional/t/too/too_many_arguments.txt | 1 + 6 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 doc/whatsnew/fragments/8667.false_negative diff --git a/doc/whatsnew/fragments/8667.false_negative b/doc/whatsnew/fragments/8667.false_negative new file mode 100644 index 000000000..3468a1264 --- /dev/null +++ b/doc/whatsnew/fragments/8667.false_negative @@ -0,0 +1,3 @@ +Fix a false negative for ``too-many-arguments`` by considering positional-only and keyword-only parameters. + +Closes #8667 diff --git a/pylint/checkers/design_analysis.py b/pylint/checkers/design_analysis.py index 701615d89..c8a53d32b 100644 --- a/pylint/checkers/design_analysis.py +++ b/pylint/checkers/design_analysis.py @@ -506,7 +506,7 @@ class MisdesignChecker(BaseChecker): # 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 diff --git a/pylint/config/argument.py b/pylint/config/argument.py index d826cbd3e..3bf990824 100644 --- a/pylint/config/argument.py +++ b/pylint/config/argument.py @@ -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, *, @@ -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, *, @@ -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, *, @@ -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, *, @@ -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, *, diff --git a/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py b/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py index 651d78f89..09bc5960f 100644 --- a/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py +++ b/tests/functional/n/non_ascii_name/non_ascii_name_pos_and_kwonly_function.py @@ -4,7 +4,7 @@ Test for names within keyword and position only function 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( diff --git a/tests/functional/t/too/too_many_arguments.py b/tests/functional/t/too/too_many_arguments.py index f4a668f53..9c7f3ab08 100644 --- a/tests/functional/t/too/too_many_arguments.py +++ b/tests/functional/t/too/too_many_arguments.py @@ -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 diff --git a/tests/functional/t/too/too_many_arguments.txt b/tests/functional/t/too/too_many_arguments.txt index f9749e949..6d727813e 100644 --- a/tests/functional/t/too/too_many_arguments.txt +++ b/tests/functional/t/too/too_many_arguments.txt @@ -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 -- cgit v1.2.1