mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
used proper type check
fix a PY-6756 PyCharm erroneously reports "too many arguments" for certain string formatting lines.
This commit is contained in:
@@ -183,7 +183,11 @@ public class PyStringFormatInspection extends PyInspection {
|
||||
}
|
||||
else if (rightExpression instanceof PySliceExpression && s != null) {
|
||||
final PyType type = myTypeEvalContext.getType(((PySliceExpression)rightExpression).getOperand());
|
||||
if (type == null || "list".equals(type.getName()) || "str".equals(type.getName())) {
|
||||
final PyType stringType = PyBuiltinCache.getInstance(rightExpression).getStringType(LanguageLevel.forElement(rightExpression));
|
||||
final PyType listType = PyBuiltinCache.getInstance(rightExpression).getListType();
|
||||
|
||||
if (type == null || PyTypeChecker.match(listType, type, myTypeEvalContext)
|
||||
|| PyTypeChecker.match(stringType, type, myTypeEvalContext)) {
|
||||
checkTypeCompatible(problemTarget, builtinCache.getStrType(),
|
||||
PyTypeParser.getTypeByName(problemTarget, s));
|
||||
return 1;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
def foo(x):
|
||||
return x
|
||||
|
||||
artist = foo(1)
|
||||
print('%s' % (artist.lower()[0:10]))
|
||||
|
||||
unicode_content = foo(u"test")
|
||||
assert isinstance(unicode_content, unicode)
|
||||
print '%s...' % unicode_content[:200]
|
||||
@@ -266,6 +266,10 @@ public class PythonInspectionsTest extends PyTestCase {
|
||||
doHighlightingTest(PyStringFormatInspection.class);
|
||||
}
|
||||
|
||||
public void testPyStringFormatInspectionSlice() { //PY-6756
|
||||
doHighlightingTest(PyStringFormatInspection.class);
|
||||
}
|
||||
|
||||
public void testPyUnnecessaryBackslashInspection() { //PY-2952
|
||||
setLanguageLevel(LanguageLevel.PYTHON27);
|
||||
doHighlightingTest(PyUnnecessaryBackslashInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user