mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-33218 Don't warn about %-formatting argument type at tuple declaration site
that might be far away from the place where the corresponding formatting operation was actually used.
This commit is contained in:
@@ -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);
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
args = ('foo', 'bar')
|
||||
s = '%d %d' % <warning descr="Unexpected type (str, str)">args</warning>
|
||||
@@ -219,6 +219,11 @@ public class PyStringFormatInspectionTest extends PyInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-33218
|
||||
public void testNoTypeMismatchOnElementsOfTupleDeclaration() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
Reference in New Issue
Block a user