@Override
  protected void invoke(@NotNull ActionContext actionContext, @NotNull PyBinaryExpression element, @NotNull ModPsiUpdater updater) {
    PyBinaryExpression topmostBinaryExpr = getTopmostBinaryExpression(element);

    LanguageLevel languageLevel = LanguageLevel.forElement(topmostBinaryExpr);
    boolean useFormatMethod = languageLevel.isAtLeast(LanguageLevel.PYTHON27);

    Function<String, String> escaper = StringUtil.escaper(false, "\"'\\");
    StringBuilder stringFormatExpr = new StringBuilder();
    List<String> parameters = new ArrayList<>();
    Pair<String, String> quotes = Pair.create("\"", "\"");
    boolean quotesDetected = false;
    TypeEvalContext context = TypeEvalContext.userInitiated(actionContext.project(), actionContext.file());
    boolean isUnicode = false;
    PyClassType unicodeType = PyBuiltinCache.getInstance(topmostBinaryExpr).getObjectType("unicode");

    for (PyExpression operand : getOperands(topmostBinaryExpr)) {
      if (operand instanceof PyStringLiteralExpression stringLiteralOperand) {
        PyType type = context.getType(operand);
        if (type != null && type.equals(unicodeType)) {
          isUnicode = true;
        }
        if (!quotesDetected) {
          quotes = PyStringLiteralCoreUtil.getQuotes(operand.getText());
          quotesDetected = true;
        }
        String value = stringLiteralOperand.getStringValue();
        if (!useFormatMethod) {
          value = value.replace("%", "%%");
        }
        stringFormatExpr.append(escaper.apply(value));
      }
      else {
        addParamToString(stringFormatExpr, parameters.size(), useFormatMethod);
        parameters.add(operand.getText());
      }
    }
    if (quotes == null) {
      quotes = Pair.create("\"", "\"");
    }
    stringFormatExpr.insert(0, quotes.getFirst());
    if (isUnicode && !StringUtil.toLowerCase(quotes.getFirst()).contains("u")) {
      stringFormatExpr.insert(0, "u");
    }
    stringFormatExpr.append(quotes.getSecond());

    PyElementGenerator elementGenerator = PyElementGenerator.getInstance(actionContext.project());

    if (!parameters.isEmpty()) {
      if (useFormatMethod) {
        stringFormatExpr.append(".format(").append(StringUtil.join(parameters, ",")).append(")");
      }
      else {
        String paramString = parameters.size() > 1 ? "(" + StringUtil.join(parameters, ",") + ")"
                                                   : StringUtil.join(parameters, ",");
        stringFormatExpr.append(" % ").append(paramString);
      }
      topmostBinaryExpr.replace(elementGenerator.createExpressionFromText(languageLevel, stringFormatExpr.toString()));
    }
    else {
      topmostBinaryExpr.replace(elementGenerator.createStringLiteralAlreadyEscaped(stringFormatExpr.toString()));
    }
  }
@Override
  protected void invoke(@NotNull ActionContext actionContext, @NotNull PyBinaryExpression element, @NotNull ModPsiUpdater updater)