PY-21166 No inspection if unknown format code is used in formatted string

This commit is contained in:
Valentina Kiryushkina
2017-05-15 14:37:54 +03:00
parent 77de45b0fd
commit 22f877a9ed
5 changed files with 18 additions and 6 deletions
@@ -391,6 +391,7 @@ INSP.too.many.args.for.fmt.string=Too many arguments for format string
INSP.too.few.args.for.fmt.string=Too few arguments for format string
INSP.incompatible.options=The format options in chunk "{0}" are incompatible
INSP.unused.mapping = Mapping key "{0}" is unused
INSP.unsupported.format.character=Unsupported format character ''{0}''
# PyMethodOverridingInspection
INSP.NAME.method.over=Method signature does not match signature of overridden method
@@ -522,10 +522,15 @@ public class PyStringFormatInspection extends PyInspection {
}
final char conversionType = chunk.getConversionType();
if (NEW_STYLE_FORMAT_CONVERSIONS.containsKey(conversionType)) {
final String[] s = NEW_STYLE_FORMAT_CONVERSIONS.get(conversionType).split(" or ");
addTypes(types, Arrays.asList(s));
hasTypeOptions = true;
if (conversionType != Character.MIN_VALUE) {
if (NEW_STYLE_FORMAT_CONVERSIONS.containsKey(conversionType)) {
final String[] s = NEW_STYLE_FORMAT_CONVERSIONS.get(conversionType).split(" or ");
addTypes(types, Arrays.asList(s));
hasTypeOptions = true;
}
else {
registerProblem(myFormatExpression, PyBundle.message("INSP.unsupported.format.character", conversionType));
}
}
if (!types.isEmpty()) {
@@ -451,7 +451,7 @@ public class PyStringFormatParser {
chunk.setPrecision(parseWhileCharacterInSet(DIGITS));
}
if (isAtSet(NEW_STYLE_CONVERSION_TYPES)) {
if (myPos < end - 1) {
chunk.setConversionType(myLiteral.charAt(myPos));
}
}
@@ -0,0 +1 @@
print(<warning descr="Unsupported format character 'q'">'{:+q}; {:+f}'</warning>.format(3.14, -3.14))
@@ -203,7 +203,12 @@ public class PyStringFormatInspectionTest extends PyTestCase {
}
});
}
//PY-21166
public void testUnsupportedFormatSpecifierNewStyleFormatting() {
doTest();
}
private void doTest() {
myFixture.configureByFile(TEST_DIRECTORY + getTestName(false) + ".py");
myFixture.enableInspections(PyStringFormatInspection.class);