PyListCompExpression (final PsiElement element) { final PyListCompExpression listCompExpression = PsiTreeUtil.getParentOfType(element, PyListCompExpression.class, false); if (listCompExpression == null){ return null; } for (PyComprehensionForComponent component : listCompExpression.getForComponents()) { final PyExpression variable = component.getIteratorVariable(); if (variable != null && PsiTreeUtil.isAncestor(variable, element, false)){ return listCompExpression; } } return null; }