boolean (@NotNull PsiElement element) { PyComprehensionElement comprehension = PsiTreeUtil.getParentOfType(element, PyComprehensionElement.class, true); if (comprehension != null) { List<PyExpression> iteratorVariables = ContainerUtil.map(comprehension.getForComponents(), it -> it.getIteratorVariable()); List<PsiElement> referencedInSelection = collectReferencedDefinitionsInSameFile(element, element.getContainingFile()); if (iteratorVariables.contains(element) || ContainerUtil.intersects(referencedInSelection, iteratorVariables)) { return true; } } return false; }