diff options
author | Yu Shao, Pang <p.yushao2@gmail.com> | 2021-07-14 16:42:25 +0800 |
---|---|---|
committer | Yu Shao, Pang <p.yushao2@gmail.com> | 2021-08-01 19:18:50 +0800 |
commit | 712dc2b0b8128f3a56ecef8347cf23bdd538069a (patch) | |
tree | cb3c41098469114e20c9fcf5017aece7e72b63a2 /pylint/checkers/classes.py | |
parent | 8ceb26dc66912e8f65adce0bc6ba22e87ceed3bb (diff) | |
download | pylint-git-712dc2b0b8128f3a56ecef8347cf23bdd538069a.tar.gz |
[unused-private-member] add logic for checking nested functions
also, improve error message for nested functions
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r-- | pylint/checkers/classes.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index 65ebe3423..c7ec58f71 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -909,6 +909,13 @@ a metaclass class method.", function_def = cast(astroid.FunctionDef, function_def) if not is_attr_private(function_def.name): continue + if isinstance(function_def.parent.scope(), astroid.FunctionDef): + # Handle nested functions + outer_fn = function_def.parent.scope() + if function_def.name in [ + n.name for n in outer_fn.nodes_of_class(astroid.Name) + ]: + continue for attribute in node.nodes_of_class(astroid.Attribute): attribute = cast(astroid.Attribute, attribute) if ( @@ -931,11 +938,18 @@ a metaclass class method.", ): break else: + name_stack = "" + curr = function_def.parent.scope() + # Generate proper names for nested functions + while curr != node: + name_stack = f"{curr.name}." + name_stack + curr = curr.parent.scope() + function_repr = f"{function_def.name}({function_def.args.as_string()})" self.add_message( "unused-private-member", node=function_def, - args=(node.name, function_repr), + args=(node.name, name_stack + function_repr), ) def _check_unused_private_variables(self, node: astroid.ClassDef) -> None: |