Fix PY-20800 'Replace with str.format method call' adds additional :s for repr

Remove explicit conversion :s because it is default for strings
This commit is contained in:
Valentina Kiryushkina
2016-09-28 14:36:09 +03:00
parent 46e0c6965d
commit fc00d0e0fc
5 changed files with 9 additions and 3 deletions
@@ -164,8 +164,7 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
out.append(f_width);
}
if ("i".equals(f_conversion) || "u".equals(f_conversion)) out.append("d");
else if ("r".equals(f_conversion)) out.append("s"); // we want our raw string as a string
else if (!"s".equals(f_conversion)) out.append(f_conversion);
else if (!"s".equals(f_conversion) && !"r".equals(f_conversion)) out.append(f_conversion);
final int lastIndexOf = out.lastIndexOf(":");
if (lastIndexOf == out.length() - 1) {
@@ -4,7 +4,7 @@ a = "{n:d} bottles of {what} on the {where}" \
{n:d} bottles
of {what}
""" \
r'\n/ take {howmuch!r:s} down \n/' \
r'\n/ take {howmuch!r} down \n/' \
ur"pass it {how:>8}" \
"{new_n:#d} {{that is, {percent:+3.2f}% less}} " \
"bottles of {what:>6} on the {where}" \
@@ -0,0 +1 @@
print('%r' <caret>% '123')
@@ -0,0 +1 @@
print('{!r}'.format('123'))
@@ -63,4 +63,9 @@ public class PyConvertFormatOperatorToMethodIntentionTest extends PyIntentionTes
public void testBytes() {
doNegativeTest(PyBundle.message("INTN.replace.with.method"));
}
// PY-20800
public void testRepr() {
doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
}
}