List<PsiNamedElement> () { PyWithItem[] items = PsiTreeUtil.getChildrenOfType(this, PyWithItem.class); List<PsiNamedElement> result = new ArrayList<>(); if (items != null) { for (PyWithItem item : items) { PyExpression targetExpression = item.getTarget(); final List<PyExpression> expressions = PyUtil.flattenedParensAndTuples(targetExpression); for (PyExpression expression : expressions) { if (expression instanceof PsiNamedElement) { result.add((PsiNamedElement)expression); } } } } return result; }