It looks to me that the repr of a collection contains a dynamic name if it is implemented in Python and hardcoded base name if it is implemented in C (OrderedDict originally was implemented in Python). Maybe just because tp_name contains full qualified name, and extracting a bare class name needs few lines of code.
There is similar issue with the io module classes: issue21861.
Since this problem is already solved for OrderedDict, I think it is easy to use this solution in other classes. Maybe factoring out the following code into helper function.
const char *classname;
classname = strrchr(Py_TYPE(self)->tp_name, '.');
if (classname == NULL)
classname = Py_TYPE(self)->tp_name;
else
classname++; |