diff --git a/ChangeLog b/ChangeLog index 30c65b48a4..85dd40a987 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,7 +14,7 @@ Release date: TBA * pyreverse: Show class has-a relationships inferred from the type-hint -Closes #4744 + Closes #4744 * Added ``ignored-parents`` option to the design checker to ignore specific classes from the ``too-many-ancestors`` check (R0901). @@ -56,6 +56,10 @@ Closes #4744 Closes #3692 +* Fix false-positive of ``unused-private-member`` when using nested functions in a class + + Closes #4673 + What's New in Pylint 2.9.6? =========================== @@ -169,10 +173,6 @@ Release date: 2021-07-20 Closes #4723 -* Fix false-positive of ``unused-private-member`` when using nested functions in a class - - Closes #4673 - What's New in Pylint 2.9.3? =========================== diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index e3d921354f..47dcd8f4b5 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -939,23 +939,22 @@ def _check_unused_private_functions(self, node: astroid.ClassDef) -> None: break else: name_stack = [] - outer_level_names = "" curr = parent_scope # Generate proper names for nested functions while curr != node: name_stack.append(curr.name) curr = curr.parent.scope() - if name_stack: - outer_level_names = f"{'.'.join(reversed(name_stack))}." + outer_level_names = f"{'.'.join(reversed(name_stack))}" - function_repr = f"{outer_level_names}{function_def.name}({function_def.args.as_string()})" self.add_message( "unused-private-member", node=function_def, args=( node.name, - function_repr, + f"{outer_level_names}.{function_def.name}({function_def.args.as_string()})".lstrip( + "." + ), ), )