From c55ba629914795ad3ec375b92eab091dc05bda1d Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Thu, 28 Jun 2012 16:08:49 +0400 Subject: [PATCH] fixed PY-6756 PyCharm erroneously reports "too many arguments" for certain string formatting lines. --- .../inspections/PyStringFormatInspection.java | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java b/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java index 51133a85a6fc..1e012cfefd8c 100644 --- a/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java @@ -181,42 +181,38 @@ public class PyStringFormatInspection extends PyInspection { return 1; } } - else if (rightExpression instanceof PySliceExpression) { - if (s != null) { - PyType type = ((PySliceExpression)rightExpression).getOperand().getType(myTypeEvalContext); - if (type != null) { - if ("list".equals(type.getName()) || "str".equals(type.getName())) { - checkTypeCompatible(problemTarget, builtinCache.getStrType(), - PyTypeParser.getTypeByName(problemTarget, s)); - return 1; - } - } - PySliceItem sliceItem = ((PySliceExpression)rightExpression).getSliceItem(); - if (sliceItem != null) { - PyExpression lower = sliceItem.getLowerBound(); - PyExpression upper = sliceItem.getUpperBound(); - PyExpression stride = sliceItem.getStride(); - if (upper instanceof PyNumericLiteralExpression) { - BigInteger lowerVal; - if (lower instanceof PyNumericLiteralExpression ) { - lowerVal = ((PyNumericLiteralExpression)lower).getBigIntegerValue(); - } - else { - lowerVal = BigInteger.ZERO; - } - int count = (((PyNumericLiteralExpression)upper).getBigIntegerValue().subtract(lowerVal)).intValue(); - int strideVal; - if (stride instanceof PyNumericLiteralExpression) - strideVal = ((PyNumericLiteralExpression)stride).getBigIntegerValue().intValue(); - else - strideVal = 1; - int res = count/strideVal; - int residue = count%strideVal == 0 ? 0 : 1; - return res + residue; - } - } - return -1; + else if (rightExpression instanceof PySliceExpression && s != null) { + final PyType type = ((PySliceExpression)rightExpression).getOperand().getType(myTypeEvalContext); + if (type == null || "list".equals(type.getName()) || "str".equals(type.getName())) { + checkTypeCompatible(problemTarget, builtinCache.getStrType(), + PyTypeParser.getTypeByName(problemTarget, s)); + return 1; } + PySliceItem sliceItem = ((PySliceExpression)rightExpression).getSliceItem(); + if (sliceItem != null) { + PyExpression lower = sliceItem.getLowerBound(); + PyExpression upper = sliceItem.getUpperBound(); + PyExpression stride = sliceItem.getStride(); + if (upper instanceof PyNumericLiteralExpression) { + BigInteger lowerVal; + if (lower instanceof PyNumericLiteralExpression ) { + lowerVal = ((PyNumericLiteralExpression)lower).getBigIntegerValue(); + } + else { + lowerVal = BigInteger.ZERO; + } + int count = (((PyNumericLiteralExpression)upper).getBigIntegerValue().subtract(lowerVal)).intValue(); + int strideVal; + if (stride instanceof PyNumericLiteralExpression) + strideVal = ((PyNumericLiteralExpression)stride).getBigIntegerValue().intValue(); + else + strideVal = 1; + int res = count/strideVal; + int residue = count%strideVal == 0 ? 0 : 1; + return res + residue; + } + } + return -1; } return -1; }