Skip to content

Commit

Permalink
update PR based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yushao2 committed Jul 18, 2021
1 parent f78d308 commit f640714
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pylint/checkers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,13 @@ def _check_unused_private_functions(self, node: astroid.ClassDef) -> None:
function_def = cast(astroid.FunctionDef, function_def)
if not is_attr_private(function_def.name):
continue
if isinstance(function_def.parent.scope(), astroid.FunctionDef):
parent_scope = function_def.parent.scope()
if isinstance(parent_scope, astroid.FunctionDef):
# Handle nested functions
outer_fn = function_def.parent.scope()
if function_def.name in [
outer_fn = 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)
Expand All @@ -937,18 +938,21 @@ def _check_unused_private_functions(self, node: astroid.ClassDef) -> None:
):
break
else:
name_stack = ""
curr = function_def.parent.scope()
name_stack = []
curr = parent_scope
# Generate proper names for nested functions
while curr != node:
name_stack = f"{curr.name}." + name_stack
name_stack.append(curr.name)
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, name_stack + function_repr),
args=(
node.name,
f"{'.'.join(reversed(name_stack))}{'.' if name_stack else ''}{function_repr}",
),
)

def _check_unused_private_variables(self, node: astroid.ClassDef) -> None:
Expand Down

0 comments on commit f640714

Please sign in to comment.