used proper type check

fix a PY-6756 PyCharm erroneously reports "too many arguments" for certain string formatting lines.
This commit is contained in:
Ekaterina Tuzova
2013-02-19 16:06:02 +04:00
parent be28564683
commit a52bcf86ff
3 changed files with 18 additions and 1 deletions
@@ -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);