boolean (@NotNull PsiElement element, PsiElement context) { if (context != null && context.getContainingFile() != element.getContainingFile()) return false; PyFunction containingFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class); if (containingFunction != null) { if (element instanceof PyTargetExpression || element instanceof PyFunction || element instanceof PyClass) { return true; } } return false; }