mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-31497: Add private helper _PyType_Name(). (#3630)
This function returns the last component of tp_name after a dot. Returns tp_name itself if it doesn't contain a dot.
This commit is contained in:
parent
132a7d7cdb
commit
4ab46d7949
6 changed files with 26 additions and 33 deletions
|
|
@ -1471,16 +1471,9 @@ odict_repr(PyODictObject *self)
|
|||
int i;
|
||||
_Py_IDENTIFIER(items);
|
||||
PyObject *pieces = NULL, *result = NULL;
|
||||
const char *classname;
|
||||
|
||||
classname = strrchr(Py_TYPE(self)->tp_name, '.');
|
||||
if (classname == NULL)
|
||||
classname = Py_TYPE(self)->tp_name;
|
||||
else
|
||||
classname++;
|
||||
|
||||
if (PyODict_SIZE(self) == 0)
|
||||
return PyUnicode_FromFormat("%s()", classname);
|
||||
return PyUnicode_FromFormat("%s()", _PyType_Name(Py_TYPE(self)));
|
||||
|
||||
i = Py_ReprEnter((PyObject *)self);
|
||||
if (i != 0) {
|
||||
|
|
@ -1532,7 +1525,8 @@ odict_repr(PyODictObject *self)
|
|||
goto Done;
|
||||
}
|
||||
|
||||
result = PyUnicode_FromFormat("%s(%R)", classname, pieces);
|
||||
result = PyUnicode_FromFormat("%s(%R)",
|
||||
_PyType_Name(Py_TYPE(self)), pieces);
|
||||
|
||||
Done:
|
||||
Py_XDECREF(pieces);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue