mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
misc python: support unions in PyStringFormatInspection
(cherry picked from commit b57bf859f88dbe3508e87c5d88609e84f8ae0452) GitOrigin-RevId: 21e3b7972f3efe1c4e5f4d52d75f5c21d3bef901
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4d95ecde4e
commit
e6495387ce
+10
-6
@@ -46,6 +46,7 @@ import com.jetbrains.python.psi.types.PyTupleType;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.PyTypeChecker;
|
||||
import com.jetbrains.python.psi.types.PyTypeParser;
|
||||
import com.jetbrains.python.psi.types.PyTypeUtil;
|
||||
import com.jetbrains.python.psi.types.PyUnionType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -166,12 +167,15 @@ public final class PyStringFormatInspection extends PyInspection {
|
||||
else if (PsiTreeUtil.instanceOf(rightExpression, SIMPLE_RHS_EXPRESSIONS)) {
|
||||
if (s != null) {
|
||||
final PyType rightType = myTypeEvalContext.getType(rightExpression);
|
||||
if (rightType instanceof PyTupleType tupleType) {
|
||||
matchEntireTupleTypes(problemTarget, tupleType);
|
||||
return tupleType.getElementCount();
|
||||
}
|
||||
else {
|
||||
checkExpressionType(rightExpression, s, problemTarget);
|
||||
|
||||
for (var member : PyTypeUtil.toStream(rightType)) {
|
||||
if (member instanceof PyTupleType tupleType) {
|
||||
matchEntireTupleTypes(problemTarget, tupleType);
|
||||
return tupleType.getElementCount();
|
||||
}
|
||||
else {
|
||||
checkExpressionType(rightExpression, s, problemTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user