mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
implement object.__format__ with PyObject_Format
This commit is contained in:
parent
3a2acb5040
commit
039c585805
1 changed files with 1 additions and 12 deletions
|
@ -3413,7 +3413,6 @@ object_format(PyObject *self, PyObject *args)
|
||||||
PyObject *format_spec;
|
PyObject *format_spec;
|
||||||
PyObject *self_as_str = NULL;
|
PyObject *self_as_str = NULL;
|
||||||
PyObject *result = NULL;
|
PyObject *result = NULL;
|
||||||
PyObject *format_meth = NULL;
|
|
||||||
Py_ssize_t format_len;
|
Py_ssize_t format_len;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
|
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
|
||||||
|
@ -3449,21 +3448,11 @@ object_format(PyObject *self, PyObject *args)
|
||||||
goto done;
|
goto done;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
return PyObject_Format(self_as_str, format_spec);
|
||||||
/* find the format function */
|
|
||||||
format_meth = PyObject_GetAttrString(self_as_str,
|
|
||||||
"__format__");
|
|
||||||
if (format_meth != NULL) {
|
|
||||||
/* and call it */
|
|
||||||
result = PyObject_CallFunctionObjArgs(format_meth,
|
|
||||||
format_spec,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
Py_XDECREF(self_as_str);
|
Py_XDECREF(self_as_str);
|
||||||
Py_XDECREF(format_meth);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue