public static PyExpr concatPyExprs(List<? extends PyExpr> pyExprs) {

    if (pyExprs.isEmpty()) {
      return EMPTY_STRING;
    }

    if (pyExprs.size() == 1) {
      // If there's only one element, simply return the expression as a String.
      return pyExprs.get(0).toPyString();
    }

    StringBuilder resultSb = new StringBuilder();

    // Use Python's list joining mechanism to speed up concatenation.
    resultSb.append("[");

    boolean isFirst = true;
    for (PyExpr pyExpr : pyExprs) {

      if (isFirst) {
        isFirst = false;
      } else {
        resultSb.append(',');
      }

      resultSb.append(pyExpr.toPyString().getText());
    }

    resultSb.append("]");
    return new PyListExpr(resultSb.toString(), Integer.MAX_VALUE);
  }
public static PyExpr concatPyExprs ( List < ? extends PyExpr > pyExprs ) { if ( pyExprs . isEmpty ( ) ) { return EMPTY_STRING ; } if ( pyExprs . size ( ) == 1 ) { return pyExprs . get ( 0 ) . toPyString ( ) ; } StringBuilder resultSb = new StringBuilder ( ) ; resultSb . append ( "[" ) ; boolean isFirst = true ; for ( PyExpr pyExpr : pyExprs ) { if ( isFirst ) { isFirst = false ; } else { resultSb . append ( ',' ) ; } resultSb . append ( pyExpr . toPyString ( ) . getText ( ) ) ; } resultSb . append ( "]" ) ; return new PyListExpr ( resultSb . toString ( ) , Integer . MAX_VALUE ) ; }
Builds one Python expression that computes the concatenation of the given Python expressions.

<p>Python doesn't allow arbitrary concatentation between types, so to ensure type safety and
consistent behavior, coerce all expressions to Strings before joining them. Python's array
joining mechanism is used in place of traditional concatenation to improve performance.

@param pyExprs The Python expressions to concatenate.
@return One Python expression that computes the concatenation of the given Python expressions.