diff options
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r-- | pylint/checkers/classes.py | 23 |
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( |