diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertToFStringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertToFStringIntention.java index 1bdc2dc7efcb..b7a74852f6c8 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertToFStringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyConvertToFStringIntention.java @@ -366,7 +366,7 @@ public class PyConvertToFStringIntention extends PyBaseIntentionAction { continue; } final char quote = invertQuote(hostStringQuote); - if (indexText.indexOf('\'') >= 0 && indexText.indexOf(quote) >= 0) { + if (indexText.indexOf(hostStringQuote) >= 0 || indexText.indexOf(quote) >= 0) { return null; } escaped.add("[" + quote + indexText + quote + "]"); diff --git a/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsHostAlternativeQuote.py b/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsHostAlternativeQuote.py new file mode 100644 index 000000000000..e9ccdb92b45b --- /dev/null +++ b/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsHostAlternativeQuote.py @@ -0,0 +1 @@ +'{foo["]}'.format(foo=undefined) \ No newline at end of file diff --git a/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsHostAlternativeQuote_after.py b/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsHostAlternativeQuote_after.py new file mode 100644 index 000000000000..e9ccdb92b45b --- /dev/null +++ b/python/testData/intentions/PyConvertToFStringIntentionTest/formatMethodIndexContainsHostAlternativeQuote_after.py @@ -0,0 +1 @@ +'{foo["]}'.format(foo=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 c79de4fd56aa..de1f4f3cb2d7 100644 --- a/python/testSrc/com/jetbrains/python/intentions/PyConvertToFStringIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/intentions/PyConvertToFStringIntentionTest.java @@ -96,6 +96,10 @@ public class PyConvertToFStringIntentionTest extends PyIntentionTestCase { doTest(); } + public void testFormatMethodIndexContainsHostAlternativeQuote() { + doTest(); + } + public void testPercentOperatorWidthAndPrecision() { doTest(); }