boolean (PsiElement referenceElement, PsiElement definition) { if (definition != null && definition.getParent() instanceof PyAssignmentExpression) return false; final PyComprehensionElement definitionComprehension = PsiTreeUtil.getParentOfType(definition, PyComprehensionElement.class); if (definitionComprehension != null && PyUtil.isOwnScopeComprehension(definitionComprehension)) { final PyComprehensionElement elementComprehension = PsiTreeUtil.getParentOfType(referenceElement, PyComprehensionElement.class); if (elementComprehension == null || !PsiTreeUtil.isAncestor(definitionComprehension, elementComprehension, false)) { return true; } } return false; }