mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
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:
parent
9adda0cdf8
commit
b3a77964ea
6 changed files with 40 additions and 20 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue