diff --git a/doc/whatsnew/fragments/8667.false_negative b/doc/whatsnew/fragments/8667.false_negative new file mode 100644 index 0000000000..3468a12648 --- /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 701615d890..b01c67647c 100644 --- a/pylint/checkers/design_analysis.py +++ b/pylint/checkers/design_analysis.py @@ -285,7 +285,7 @@ class MisdesignChecker(BaseChecker): ( "max-args", { - "default": 5, + "default": 7, "type": "int", "metavar": "", "help": "Maximum number of arguments for function / method.", @@ -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 diff --git a/pylint/config/argument.py b/pylint/config/argument.py index d826cbd3e6..3bf9908241 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/a/async_functions.txt b/tests/functional/a/async_functions.txt index 63823cced7..409f247cfc 100644 --- a/tests/functional/a/async_functions.txt +++ b/tests/functional/a/async_functions.txt @@ -1,7 +1,7 @@ redefined-builtin:5:0:5:14:next:Redefining built-in 'next':UNDEFINED unused-argument:8:30:8:34:some_function:Unused argument 'arg2':HIGH bad-super-call:22:8:22:31:Class.some_method:Bad first argument 'OtherClass' given to super():UNDEFINED -too-many-arguments:26:0:26:26:complex_function:Too many arguments (10/5):UNDEFINED +too-many-arguments:26:0:26:26:complex_function:Too many arguments (10/7):UNDEFINED too-many-branches:26:0:26:26:complex_function:Too many branches (13/12):UNDEFINED too-many-return-statements:26:0:26:26:complex_function:Too many return statements (10/6):UNDEFINED dangerous-default-value:57:0:57:14:func:Dangerous default value [] as argument:UNDEFINED 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 651d78f894..09bc5960fd 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 @@ 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 f4a668f53f..412a257692 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(par1, par2, par3, par4, par5, /, par6, par7, *args, par8="apple", **kwargs): + return par1, par2, par3, par4, par5, par6, par7, par8, args, kwargs diff --git a/tests/functional/t/too/too_many_arguments.txt b/tests/functional/t/too/too_many_arguments.txt index f9749e9495..ffbe8aa245 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:3:0:3:19:stupid_function:Too many arguments (9/7):UNDEFINED +too-many-arguments:36:0:36:9:name1:Too many arguments (8/7):UNDEFINED diff --git a/tests/functional/t/too/too_many_locals.py b/tests/functional/t/too/too_many_locals.py index 34395871d7..e3ce59514a 100644 --- a/tests/functional/t/too/too_many_locals.py +++ b/tests/functional/t/too/too_many_locals.py @@ -29,13 +29,16 @@ def too_many_locals_function(): # [too-many-locals] args15 = args14 * 15 return args15 -def too_many_arguments_function(arga, argu, argi, arge, argt, args): # [too-many-arguments] +# +1: [too-many-arguments] +def too_many_arguments_function(arga, argu, argi, arge, argt, args, arg7, arg8): """pylint will complain about too many arguments.""" arga = argu arga += argi arga += arge arga += argt arga += args + arga += arg7 + arga += arg8 return arga def ignored_arguments_function(arga, argu, argi, diff --git a/tests/functional/t/too/too_many_locals.txt b/tests/functional/t/too/too_many_locals.txt index 19272626f1..b99ee5e7b5 100644 --- a/tests/functional/t/too/too_many_locals.txt +++ b/tests/functional/t/too/too_many_locals.txt @@ -1,3 +1,3 @@ too-many-locals:4:0:4:12:function:Too many local variables (16/15):UNDEFINED too-many-locals:12:0:12:28:too_many_locals_function:Too many local variables (16/15):UNDEFINED -too-many-arguments:32:0:32:31:too_many_arguments_function:Too many arguments (6/5):UNDEFINED +too-many-arguments:33:0:33:31:too_many_arguments_function:Too many arguments (8/7):UNDEFINED diff --git a/tests/functional/u/unexpected_special_method_signature.py b/tests/functional/u/unexpected_special_method_signature.py index 146308b035..08474182d9 100644 --- a/tests/functional/u/unexpected_special_method_signature.py +++ b/tests/functional/u/unexpected_special_method_signature.py @@ -1,7 +1,7 @@ """Test for special methods implemented incorrectly.""" # pylint: disable=missing-docstring, unused-argument, too-few-public-methods -# pylint: disable=invalid-name,too-many-arguments,bad-staticmethod-argument +# pylint: disable=invalid-name,bad-staticmethod-argument class Invalid: diff --git a/tests/primer/packages_to_prime.json b/tests/primer/packages_to_prime.json index a7c2796e7a..c828db9e2c 100644 --- a/tests/primer/packages_to_prime.json +++ b/tests/primer/packages_to_prime.json @@ -23,7 +23,7 @@ "home-assistant": { "branch": "dev", "directories": ["homeassistant"], - "url": "https://github.com/home-assistant/core.git" + "url": "https://github.com/home-assistant/core" }, "music21": { "branch": "master",