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:
Serhiy Storchaka 2017-09-17 21:11:04 +03:00 committed by GitHub
parent 132a7d7cdb
commit 4ab46d7949
6 changed files with 26 additions and 33 deletions

View file

@ -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);