From 2262e51fa9f106794c42f32e2b83785c39ef71a2 Mon Sep 17 00:00:00 2001 From: Valentina Kiryushkina Date: Mon, 26 Sep 2016 14:53:33 +0300 Subject: [PATCH] Fix PY-20876 'Replace with str.format method call' is messed up with sets --- .../intentions/ConvertFormatOperatorToMethodIntention.java | 6 ++---- .../PyConvertFormatOperatorToMethodIntentionTest/set.py | 1 + .../set_after.py | 1 + .../PyConvertFormatOperatorToMethodIntentionTest.java | 7 ++++++- 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 python/testData/intentions/PyConvertFormatOperatorToMethodIntentionTest/set.py create mode 100644 python/testData/intentions/PyConvertFormatOperatorToMethodIntentionTest/set_after.py diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java index 753d6db758b8..16998e06b103 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/ConvertFormatOperatorToMethodIntention.java @@ -304,10 +304,8 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction } } } - else if (rhsType instanceof PyCollectionType) { - if ("dict".equals(rhsType.getName())) { - target.append("(**").append(paramText).append(")"); - } + else if (rhsType instanceof PyCollectionType && "dict".equals(rhsType.getName())) { + target.append("(**").append(paramText).append(")"); } else target.append("(").append(paramText).append(")"); // tuple is ok as is // Correctly handle multiline implicitly concatenated string literals (PY-9176) diff --git a/python/testData/intentions/PyConvertFormatOperatorToMethodIntentionTest/set.py b/python/testData/intentions/PyConvertFormatOperatorToMethodIntentionTest/set.py new file mode 100644 index 000000000000..ee39c0e392d3 --- /dev/null +++ b/python/testData/intentions/PyConvertFormatOperatorToMethodIntentionTest/set.py @@ -0,0 +1 @@ +print('%s' % {1, 2}) \ No newline at end of file diff --git a/python/testData/intentions/PyConvertFormatOperatorToMethodIntentionTest/set_after.py b/python/testData/intentions/PyConvertFormatOperatorToMethodIntentionTest/set_after.py new file mode 100644 index 000000000000..6d879b230d07 --- /dev/null +++ b/python/testData/intentions/PyConvertFormatOperatorToMethodIntentionTest/set_after.py @@ -0,0 +1 @@ +print('{}'.format({1, 2})) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/intentions/PyConvertFormatOperatorToMethodIntentionTest.java b/python/testSrc/com/jetbrains/python/intentions/PyConvertFormatOperatorToMethodIntentionTest.java index a8a09adb9f38..e31ec3ad703e 100644 --- a/python/testSrc/com/jetbrains/python/intentions/PyConvertFormatOperatorToMethodIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/intentions/PyConvertFormatOperatorToMethodIntentionTest.java @@ -82,5 +82,10 @@ public class PyConvertFormatOperatorToMethodIntentionTest extends PyIntentionTes // PY-20803 public void testStarWidthPrecision() { doNegativeTest(PyBundle.message("INTN.replace.with.method")); - } + } + + // PY-20876 + public void testSet() { + doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26); + } } \ No newline at end of file