boolean (@NotNull PyStringElement stringElement, boolean checkContainingFString) { if (stringElement.isTripleQuoted() || !stringElement.isTerminated()) return false; if (checkContainingFString) { PyFormattedStringElement parentFString = PsiTreeUtil.getParentOfType(stringElement, PyFormattedStringElement.class, true, PyStatement.class); char targetQuote = PyStringLiteralUtil.flipQuote(stringElement.getQuote().charAt(0)); if (parentFString != null && LanguageLevel.forElement(stringElement).isOlderThan(LanguageLevel.PYTHON312)) { boolean parentFStringUsesTargetQuotes = parentFString.getQuote().equals(Character.toString(targetQuote)); if (parentFStringUsesTargetQuotes) return false; boolean conversionIntroducesBackslashEscapedQuote = stringElement.textContains(targetQuote); if (conversionIntroducesBackslashEscapedQuote) return false; } } PyFormattedStringElement fStringElement = as(stringElement, PyFormattedStringElement.class); if (fStringElement != null) { Collection<PyStringElement> innerStrings = PsiTreeUtil.findChildrenOfType(fStringElement, PyStringElement.class); if (ContainerUtil.exists(innerStrings, s -> !canBeConverted(s, false))) { return false; } } return true; }