PyExpression (@NotNull PyExpression expression, char desiredQuote) { var expressionCopy = (PyExpression)expression.copy(); var valueStringElements = getStringElements(expressionCopy); for (var valueStringElement : valueStringElements) { char actualQuote = valueStringElement.getQuote().charAt(0); PyStringElement elementToReplace = valueStringElement; if (actualQuote != desiredQuote) { elementToReplace = PyQuotesUtil.createCopyWithConvertedQuotes(valueStringElement); } valueStringElement.replace(elementToReplace); } return expressionCopy; }