mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +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
|
|
@ -4067,7 +4067,8 @@ static PyObject *
|
|||
count_repr(countobject *lz)
|
||||
{
|
||||
if (lz->cnt != PY_SSIZE_T_MAX)
|
||||
return PyUnicode_FromFormat("count(%zd)", lz->cnt);
|
||||
return PyUnicode_FromFormat("%s(%zd)",
|
||||
_PyType_Name(Py_TYPE(lz)), lz->cnt);
|
||||
|
||||
if (PyLong_Check(lz->long_step)) {
|
||||
long step = PyLong_AsLong(lz->long_step);
|
||||
|
|
@ -4076,11 +4077,14 @@ count_repr(countobject *lz)
|
|||
}
|
||||
if (step == 1) {
|
||||
/* Don't display step when it is an integer equal to 1 */
|
||||
return PyUnicode_FromFormat("count(%R)", lz->long_cnt);
|
||||
return PyUnicode_FromFormat("%s(%R)",
|
||||
_PyType_Name(Py_TYPE(lz)),
|
||||
lz->long_cnt);
|
||||
}
|
||||
}
|
||||
return PyUnicode_FromFormat("count(%R, %R)",
|
||||
lz->long_cnt, lz->long_step);
|
||||
return PyUnicode_FromFormat("%s(%R, %R)",
|
||||
_PyType_Name(Py_TYPE(lz)),
|
||||
lz->long_cnt, lz->long_step);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
@ -4220,9 +4224,12 @@ static PyObject *
|
|||
repeat_repr(repeatobject *ro)
|
||||
{
|
||||
if (ro->cnt == -1)
|
||||
return PyUnicode_FromFormat("repeat(%R)", ro->element);
|
||||
return PyUnicode_FromFormat("%s(%R)",
|
||||
_PyType_Name(Py_TYPE(ro)), ro->element);
|
||||
else
|
||||
return PyUnicode_FromFormat("repeat(%R, %zd)", ro->element, ro->cnt);
|
||||
return PyUnicode_FromFormat("%s(%R, %zd)",
|
||||
_PyType_Name(Py_TYPE(ro)), ro->element,
|
||||
ro->cnt);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue