PsiElement (@Nullable PyExpression expression) { final PsiElement elementToAnalyze = PyPsiUtils.flattenParens(expression); if (elementToAnalyze instanceof PyReferenceExpression) { final TypeEvalContext context = TypeEvalContext.deepCodeInsight(elementToAnalyze.getProject()); final PyResolveContext resolveContext = PyResolveContext.defaultContext(context); return StreamEx .of(((PyReferenceExpression)elementToAnalyze).multiFollowAssignmentsChain(resolveContext)) .map(ResolveResult::getElement) .findFirst(Objects::nonNull) .map(e -> e instanceof PyExpression ? PyPsiUtils.flattenParens((PyExpression)e) : e) .orElse(null); } return elementToAnalyze; }