mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Add a format specifier %R to PyUnicode_FromFormat(), which embeds
the result of a call to PyObject_Repr() into the string. This makes it possible to simplify many repr implementations. PyUnicode_FromFormat() uses two steps to create the final string: A first pass through the format string determines the size of the final string and a second pass creates the string. To avoid calling PyObject_Repr() twice for each %R specifier, PyObject_Repr() is called during the size calculation step and the results are stored in an array (whose size is determined at the start by counting %R specifiers).
This commit is contained in:
parent
94b59bb144
commit
7569dfe11d
12 changed files with 125 additions and 149 deletions
|
@ -261,11 +261,9 @@ method_repr(PyMethodObject *a)
|
|||
result = PyUnicode_FromFormat("<unbound method %s.%s>",
|
||||
sklassname, sfuncname);
|
||||
else {
|
||||
result = PyUnicode_FromFormat("<bound method %s.%s of ",
|
||||
sklassname, sfuncname);
|
||||
/* XXX Shouldn't use repr() here! */
|
||||
PyUnicode_AppendAndDel(&result, PyObject_Repr(self));
|
||||
PyUnicode_AppendAndDel(&result, PyUnicode_FromString(">"));
|
||||
/* XXX Shouldn't use repr()/%R here! */
|
||||
result = PyUnicode_FromFormat("<bound method %s.%s of %R>",
|
||||
sklassname, sfuncname, self);
|
||||
}
|
||||
Py_XDECREF(funcname);
|
||||
Py_XDECREF(klassname);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue