PyExpression (@NotNull PyBinaryExpression expression, @NotNull Project project) { final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project); PyExpression left = expression.getLeftExpression(); PyExpression right = expression.getRightExpression(); PsiElement operator = expression.getPsiOperator(); while (isComparisonExpression(left)) { assert operator != null; right = elementGenerator.createBinaryExpression(operator.getText(), ((PyBinaryExpression)left).getRightExpression(), right); operator = ((PyBinaryExpression)left).getPsiOperator(); left = ((PyBinaryExpression)left).getLeftExpression(); } return right; }