From 880095c7266134a218e5f97075d1adeaa5b34b79 Mon Sep 17 00:00:00 2001 From: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Date: Fri, 2 Sep 2022 09:35:16 +0200 Subject: Fix false positive for ``too-many-function-args`` when a function call is assigned to a class attribute inside the class where the function is defined. (#7395) Closes #6592 --- pylint/checkers/typecheck.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pylint/checkers/typecheck.py') diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 9732ede78..f2518beae 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -1458,6 +1458,19 @@ accessed. Python regular expressions are accepted.", keyword_args += list(already_filled_keywords) num_positional_args += implicit_args + already_filled_positionals + # Decrement `num_positional_args` by 1 when a function call is assigned to a class attribute + # inside the class where the function is defined. + # This avoids emitting `too-many-function-args` since `num_positional_args` + # 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 + ): + num_positional_args -= 1 + # Analyze the list of formal parameters. args = list(itertools.chain(called.args.posonlyargs or (), called.args.args)) num_mandatory_parameters = len(args) - len(called.args.defaults) -- cgit v1.2.1