boolean (@NotNull PsiElement element) { if (element instanceof PyExpression && PyUtil.isInstanceAttribute((PyExpression)element)) { PyClass elementClass = PsiTreeUtil.getParentOfType(element, PyClass.class); PyClass referenceClass = PsiTreeUtil.getParentOfType(myElement, PyClass.class); if (referenceClass != null && referenceClass.isSubclass(elementClass, null)) { String elementName = ((PyTargetExpression) element).getReferencedName(); String referenceName = myElement.getStringValue(); if (Objects.equals(elementName, referenceName)) { return true; } } } return false; }