Issue #13350: Replace most usages of PyUnicode_Format by PyUnicode_FromFormat.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index bbc529a..cf4f276 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2121,9 +2121,8 @@
listindex(PyListObject *self, PyObject *args)
{
Py_ssize_t i, start=0, stop=Py_SIZE(self);
- PyObject *v, *format_tuple, *err_string;
+ PyObject *v;
PyObject *start_obj = NULL, *stop_obj = NULL;
- static PyObject *err_format = NULL;
if (!PyArg_ParseTuple(args, "O|OO:index", &v, &start_obj, &stop_obj))
return NULL;
@@ -2153,20 +2152,7 @@
else if (cmp < 0)
return NULL;
}
- if (err_format == NULL) {
- err_format = PyUnicode_FromString("%r is not in list");
- if (err_format == NULL)
- return NULL;
- }
- format_tuple = PyTuple_Pack(1, v);
- if (format_tuple == NULL)
- return NULL;
- err_string = PyUnicode_Format(err_format, format_tuple);
- Py_DECREF(format_tuple);
- if (err_string == NULL)
- return NULL;
- PyErr_SetObject(PyExc_ValueError, err_string);
- Py_DECREF(err_string);
+ PyErr_Format(PyExc_ValueError, "%R is not in list", v);
return NULL;
}