PsiElement (@NotNull PyStringLiteralExpression host) { final PsiElement comprehensionPart = PsiTreeUtil.findFirstParent(host, element -> { // Any comprehension component and its result are represented as children expressions of the comprehension element. // Only they have respective nodes in CFG and thus can be used as anchors return element instanceof PyExpression && element.getParent() instanceof PyComprehensionElement; }); if (comprehensionPart != null) { return comprehensionPart; } return PsiTreeUtil.getParentOfType(host, PyStatement.class); }