Skip to content

Commit

Permalink
[unused-private-member] Handle the case using self to access members
Browse files Browse the repository at this point in the history
As seen in issue pylint-dev#4644
  • Loading branch information
Pierre-Sassoulas committed Jul 1, 2021
1 parent c822678 commit 1811324
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pylint/checkers/classes.py
Expand Up @@ -949,7 +949,7 @@ def _check_unused_private_variables(self, node: astroid.ClassDef) -> None:
if (
isinstance(child, astroid.Attribute)
and child.attrname == assign_name.name
and child.expr.name in ("cls", node.name)
and child.expr.name in ("self", "cls", node.name)
):
break
else:
Expand Down
16 changes: 16 additions & 0 deletions tests/functional/u/unused/unused_private_member.py
Expand Up @@ -87,3 +87,19 @@ def __b(cls):
@classmethod
def __c(cls):
pass


class Klass:
"""Regression test for 4644"""

__seventyseven = 77
__ninetyone = 91

def __init__(self):
self.twentyone = 21 * (1 / (self.__seventyseven + 33)) % 100
self.ninetyfive = Klass.__ninetyone + 4


k = Klass()
print(k.twentyone)
print(k.ninetyfive)

0 comments on commit 1811324

Please sign in to comment.