summaryrefslogtreecommitdiff
path: root/pylint/checkers/classes.py
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-30 22:32:53 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-30 23:13:20 +0200
commitaa6d91f45407544e49287ca5b43d6c86d317f5a7 (patch)
tree50fb2ac887d9e35890a29f48e5be804a4e4a863c /pylint/checkers/classes.py
parentefc35c3c40622f419ea07f698c029f13fb9fed52 (diff)
downloadpylint-git-aa6d91f45407544e49287ca5b43d6c86d317f5a7.tar.gz
[unused-private-member] Handle the case with Call node
As seen in issue #4638
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r--pylint/checkers/classes.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index 6fffd2b16..a85e216c5 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -909,14 +909,29 @@ a metaclass class method.",
continue
for attribute in node.nodes_of_class(astroid.Attribute):
attribute = cast(astroid.Attribute, attribute)
- if attribute.expr is None: # attribute.expr is probably not really an Optional ?
+ if attribute.expr is None:
+ # attribute.expr is an Optional[NodeNG] it can be None
continue
if (
- attribute.attrname == function_def.name
- and attribute.scope() != function_def # We ignore recursive calls
- and attribute.expr.name in ("self", node.name)
+ attribute.attrname != function_def.name
+ or attribute.scope() == function_def
):
+ # We ignore recursive calls
+ continue
+ if isinstance(attribute.expr, astroid.Name) and attribute.expr.name in (
+ "self",
+ node.name,
+ ):
+ # self.__attrname / node_name.__attrname
break
+ if isinstance(attribute.expr, astroid.Call):
+ # type(self).__attrname
+ inferred = safe_infer(attribute.expr)
+ if (
+ isinstance(inferred, astroid.ClassDef)
+ and inferred.name == node.name
+ ):
+ break
else:
function_repr = f"{function_def.name}({function_def.args.as_string()})"
self.add_message(