diff --git a/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java b/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java index 1242ad237a76..bea2c31d2b76 100644 --- a/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyStringFormatInspection.java @@ -135,20 +135,28 @@ public class PyStringFormatInspection extends PyInspection { else if (rightExpression instanceof PyParenthesizedExpression) { final PyExpression rhs = ((PyParenthesizedExpression)rightExpression).getContainedExpression(); if (rhs != null) { - return inspectArguments(rhs, rhs); + return inspectArguments(rhs, problemTarget); } } else if (rightExpression instanceof PyTupleExpression) { - final PyExpression[] expressions = ((PyTupleExpression)rightExpression).getElements(); - int i = 1; - for (PyExpression expression : expressions) { - final String formatSpec = myFormatSpec.get(Integer.toString(i)); - if (formatSpec != null) { - checkExpressionType(expression, formatSpec, expression); + if (PsiTreeUtil.isAncestor(problemTarget, rightExpression, false)) { + final PyExpression[] expressions = ((PyTupleExpression)rightExpression).getElements(); + int i = 1; + for (PyExpression expression : expressions) { + final String formatSpec = myFormatSpec.get(Integer.toString(i)); + if (formatSpec != null) { + checkExpressionType(expression, formatSpec, expression); + } + ++i; } - ++i; + return expressions.length; + } + else { + final PyTupleType tupleType = (PyTupleType)myTypeEvalContext.getType(rightExpression); + assert tupleType != null; + matchEntireTupleTypes(problemTarget, tupleType); + return tupleType.getElementCount(); } - return expressions.length; } else if (rightExpression instanceof PyDictLiteralExpression) { return inspectDict(rightExpression, problemTarget, false); diff --git a/python/testData/inspections/PyStringFormatInspection/NoTypeMismatchOnElementsOfTupleDeclaration.py b/python/testData/inspections/PyStringFormatInspection/NoTypeMismatchOnElementsOfTupleDeclaration.py new file mode 100644 index 000000000000..02f6f17e074b --- /dev/null +++ b/python/testData/inspections/PyStringFormatInspection/NoTypeMismatchOnElementsOfTupleDeclaration.py @@ -0,0 +1,2 @@ +args = ('foo', 'bar') +s = '%d %d' % args \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyStringFormatInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyStringFormatInspectionTest.java index 7b49980e1c9c..233ee7e4647a 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyStringFormatInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyStringFormatInspectionTest.java @@ -219,6 +219,11 @@ public class PyStringFormatInspectionTest extends PyInspectionTestCase { doTest(); } + // PY-33218 + public void testNoTypeMismatchOnElementsOfTupleDeclaration() { + doTest(); + } + @NotNull @Override protected Class getInspectionClass() {