summaryrefslogtreecommitdiff
path: root/pylint/checkers/typecheck.py
diff options
context:
space:
mode:
authorMark Byrne <31762852+mbyrnepr2@users.noreply.github.com>2022-09-02 09:35:16 +0200
committerGitHub <noreply@github.com>2022-09-02 09:35:16 +0200
commit880095c7266134a218e5f97075d1adeaa5b34b79 (patch)
tree468826b8917931a9997aab7e0a40473c2953d2c4 /pylint/checkers/typecheck.py
parentbcd4ca3052411e8c0823712d38cb970e354713f6 (diff)
downloadpylint-git-880095c7266134a218e5f97075d1adeaa5b34b79.tar.gz
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
Diffstat (limited to 'pylint/checkers/typecheck.py')
-rw-r--r--pylint/checkers/typecheck.py13
1 files changed, 13 insertions, 0 deletions
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)