mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
Fix PY-19749 'Replace with str.format method call' should not add positional id
This commit is contained in:
@@ -123,7 +123,6 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
|
||||
int index = openPos + 1; // from quote to first in-string char
|
||||
StringBuilder out = new StringBuilder(text.subSequence(0, openPos+1));
|
||||
if (!hasPrefix) out.insert(0, prefix);
|
||||
int position_count = 0;
|
||||
Matcher scanner = FORMAT_PATTERN.matcher(text);
|
||||
while (scanner.find(index)) {
|
||||
// store previous non-format part
|
||||
@@ -147,10 +146,6 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
|
||||
out.append(f_key);
|
||||
usesNamedFormat = true;
|
||||
}
|
||||
else {
|
||||
out.append(position_count);
|
||||
position_count += 1;
|
||||
}
|
||||
if ("r".equals(f_conversion)) out.append("!r");
|
||||
// don't convert %s -> !s, for %s is the normal way to output the default representation
|
||||
out.append(":");
|
||||
@@ -172,8 +167,12 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
|
||||
}
|
||||
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 out.append(f_conversion);
|
||||
//
|
||||
else if (!"s".equals(f_conversion)) out.append(f_conversion);
|
||||
|
||||
final int lastIndexOf = out.lastIndexOf(":");
|
||||
if (lastIndexOf == out.length() - 1) {
|
||||
out.deleteCharAt(lastIndexOf);
|
||||
}
|
||||
out.append("}");
|
||||
}
|
||||
index = scanner.end();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
print('{quantity:s} pounds of '
|
||||
'{type:s}'.format(quantity=42, type='spam'))
|
||||
print('{quantity} pounds of '
|
||||
'{type}'.format(quantity=42, type='spam'))
|
||||
@@ -1,2 +1,2 @@
|
||||
print u"\N{LATIN SMALL LETTER B}{0:s}\N{NUMBER SIGN}\
|
||||
{1:s}\N{LATIN SMALL LETTER B}".format(str1, str2)
|
||||
print u"\N{LATIN SMALL LETTER B}{}\N{NUMBER SIGN}\
|
||||
{}\N{LATIN SMALL LETTER B}".format(str1, str2)
|
||||
@@ -1,13 +1,13 @@
|
||||
n = 8
|
||||
a = "{n:d} bottles of {what:s} on the {where:s}" \
|
||||
a = "{n:d} bottles of {what} on the {where}" \
|
||||
"""
|
||||
{n:d} bottles
|
||||
of {what:s}
|
||||
of {what}
|
||||
""" \
|
||||
r'\n/ take {howmuch!r:s} down \n/' \
|
||||
ur"pass it {how:>8s}" \
|
||||
ur"pass it {how:>8}" \
|
||||
"{new_n:#d} {{that is, {percent:+3.2f}% less}} " \
|
||||
"bottles of {what:>6s} on the {where:s}" \
|
||||
"bottles of {what:>6} on the {where}" \
|
||||
.format(n=n, where="wall", howmuch=u'one', how="'round\t", new_n=(n - 1), percent=100 * (1 - ((n - 1.0) / n)),
|
||||
what="beer")
|
||||
print a
|
||||
|
||||
@@ -1 +1 @@
|
||||
print("|\077{0:>20s}FOO! {1: 5.3F}%\n|{2:<15s} {3:<10d}-torn-off, {4:+#05d}".format("right-->", 12, "<--left", -10, 20))
|
||||
print("|\077{:>20}FOO! {: 5.3F}%\n|{:<15} {:<10d}-torn-off, {:+#05d}".format("right-->", 12, "<--left", -10, 20))
|
||||
@@ -1,3 +1,3 @@
|
||||
# coding=utf-8
|
||||
x = u'привет'
|
||||
y = u"{0:s}".format(x)
|
||||
y = u"{}".format(x)
|
||||
Reference in New Issue
Block a user