Skip to content

Commit

Permalink
PY-33218 Don't warn about %-formatting argument type at tuple declara…
Browse files Browse the repository at this point in the history
…tion site

that might be far away from the place where the corresponding formatting
operation was actually used.
  • Loading branch information
east825 committed Jan 9, 2019
1 parent f719132 commit 85cf94e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,28 @@ else if (rightExpression instanceof PyCallExpression) {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
args = ('foo', 'bar')
s = '%d %d' % <warning descr="Unexpected type (str, str)">args</warning>
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ public void testSOEOnReassignedFormatArgument() {
doTest();
}

// PY-33218
public void testNoTypeMismatchOnElementsOfTupleDeclaration() {
doTest();
}

@NotNull
@Override
protected Class<? extends PyInspection> getInspectionClass() {
Expand Down

0 comments on commit 85cf94e

Please sign in to comment.