PyExpression (@NotNull LanguageLevel languageLevel, @NotNull String text) { final PsiFile dummyFile = createDummyFile(languageLevel, text); final PsiElement element = dummyFile.getFirstChild(); if (element instanceof PyExpressionStatement) { return ((PyExpressionStatement)element).getExpression(); } throw new IncorrectOperationException("could not parse text as expression: " + text); }