bpo-27541: Reprs of subclasses of some classes now contain actual type name. (#3631)

Affected classes are bytearray, array, deque, defaultdict, count and repeat.
This commit is contained in:
Serhiy Storchaka 2017-09-21 14:24:13 +03:00 committed by GitHub
parent 9adda0cdf8
commit b3a77964ea
6 changed files with 40 additions and 20 deletions

View file

@ -2307,7 +2307,8 @@ array_repr(arrayobject *a)
len = Py_SIZE(a);
typecode = a->ob_descr->typecode;
if (len == 0) {
return PyUnicode_FromFormat("array('%c')", (int)typecode);
return PyUnicode_FromFormat("%s('%c')",
_PyType_Name(Py_TYPE(a)), (int)typecode);
}
if (typecode == 'u') {
v = array_array_tounicode_impl(a);
@ -2317,7 +2318,8 @@ array_repr(arrayobject *a)
if (v == NULL)
return NULL;
s = PyUnicode_FromFormat("array('%c', %R)", (int)typecode, v);
s = PyUnicode_FromFormat("%s('%c', %R)",
_PyType_Name(Py_TYPE(a)), (int)typecode, v);
Py_DECREF(v);
return s;
}