mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix PY-20599 False positive for %a format specifier
This commit is contained in:
@@ -83,6 +83,7 @@ public class PyStringFormatInspection extends PyInspection {
|
||||
.put('G', "float")
|
||||
.put('c', "str")
|
||||
.put('r', "str")
|
||||
.put('a', "str")
|
||||
.put('s', "str")
|
||||
.put('b', "bytes")
|
||||
.build();
|
||||
@@ -402,7 +403,8 @@ public class PyStringFormatInspection extends PyInspection {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (PERCENT_FORMAT_CONVERSIONS.containsKey(conversionType)) {
|
||||
final LanguageLevel languageLevel = LanguageLevel.forElement(formatExpression);
|
||||
if (PERCENT_FORMAT_CONVERSIONS.containsKey(conversionType) && !(!languageLevel.isPy3K() && conversionType == 'a')) {
|
||||
myFormatSpec.put(mappingKey, PERCENT_FORMAT_CONVERSIONS.get(conversionType));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ public class PyStringFormatParser {
|
||||
private static final String CONVERSION_FLAGS = "#0- +";
|
||||
private static final String DIGITS = "0123456789";
|
||||
private static final String LENGTH_MODIFIERS = "hlL";
|
||||
private static final String VALID_CONVERSION_TYPES = "diouxXeEfFgGcrsb";
|
||||
private static final String VALID_CONVERSION_TYPES = "diouxXeEfFgGcrsba";
|
||||
|
||||
// new style strings
|
||||
private static final String ALIGN_SYMBOLS = "<>=^";
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
"foo %a" % "foo"
|
||||
<warning descr="Format specifier character missing">"foo %q"</warning> % "foo"
|
||||
@@ -552,4 +552,11 @@ public class PyStringFormatParserTest extends TestCase {
|
||||
assertEquals("a", chunk.getMappingKeyElementIndex());
|
||||
assertEquals('d', chunk.getConversionType());
|
||||
}
|
||||
|
||||
public void testAsciiFormatSpecifierOldStyleFormat() {
|
||||
final List<FormatStringChunk> chunks = parsePercentFormat("%a");
|
||||
assertEquals(1, chunks.size());
|
||||
final PercentSubstitutionChunk chunk = (PercentSubstitutionChunk)chunks.get(0);
|
||||
assertEquals('a', chunk.getConversionType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.jetbrains.python.inspections;
|
||||
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
|
||||
/**
|
||||
* @author vlan
|
||||
@@ -188,6 +189,16 @@ public class PyStringFormatInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-20599
|
||||
public void testPy3kAsciiFormatSpecifier() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON35, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTest();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(TEST_DIRECTORY + getTestName(false) + ".py");
|
||||
myFixture.enableInspections(PyStringFormatInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user