diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertToFStringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertToFStringIntention.java index b7a74852f6c8..4a6ac8522e7d 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertToFStringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertToFStringIntention.java @@ -360,6 +360,9 @@ public class PyConvertToFStringIntention extends PyBaseIntentionAction { escaped.add(part); } else if (part.startsWith("[")) { + if (part.contains("\\")) { + return null; + } final String indexText = part.substring(1, part.length() - 1); if (indexText.matches("\\d+")) { escaped.add(part); diff --git a/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsBackslash.py b/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsBackslash.py new file mode 100644 index 000000000000..bc5fc6d168ce --- /dev/null +++ b/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsBackslash.py @@ -0,0 +1 @@ +'{0[\\]}'.format(undefined) \ No newline at end of file diff --git a/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsBackslash_after.py b/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsBackslash_after.py new file mode 100644 index 000000000000..bc5fc6d168ce --- /dev/null +++ b/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsBackslash_after.py @@ -0,0 +1 @@ +'{0[\\]}'.format(undefined) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/intentions/PyConvertToFStringIntentionTest.java b/python/testSrc/com/jetbrains/python/intentions/PyConvertToFStringIntentionTest.java index de1f4f3cb2d7..2f028999b558 100644 --- a/python/testSrc/com/jetbrains/python/intentions/PyConvertToFStringIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/intentions/PyConvertToFStringIntentionTest.java @@ -99,6 +99,10 @@ public class PyConvertToFStringIntentionTest extends PyIntentionTestCase { public void testFormatMethodIndexContainsHostAlternativeQuote() { doTest(); } + + public void testFormatMethodIndexContainsBackslash() { + doTest(); + } public void testPercentOperatorWidthAndPrecision() { doTest();