diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-21 11:24:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-21 11:24:13 (GMT) |
commit | b3a77964ea89a488fc0e920e3db6d8477279f19b (patch) | |
tree | 880d5770553aac324a7b29efdb233eca0cfbd38a /Modules | |
parent | 9adda0cdf89432386b7a04444a6199b580d287a1 (diff) | |
download | cpython-b3a77964ea89a488fc0e920e3db6d8477279f19b.zip cpython-b3a77964ea89a488fc0e920e3db6d8477279f19b.tar.gz cpython-b3a77964ea89a488fc0e920e3db6d8477279f19b.tar.bz2 |
bpo-27541: Reprs of subclasses of some classes now contain actual type name. (#3631)
Affected classes are bytearray, array, deque, defaultdict, count and repeat.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_collectionsmodule.c | 11 | ||||
-rw-r--r-- | Modules/arraymodule.c | 6 | ||||
-rw-r--r-- | Modules/itertoolsmodule.c | 19 |
3 files changed, 24 insertions, 12 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 8766d86..e78399d 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1384,10 +1384,12 @@ deque_repr(PyObject *deque) return NULL; } if (((dequeobject *)deque)->maxlen >= 0) - result = PyUnicode_FromFormat("deque(%R, maxlen=%zd)", - aslist, ((dequeobject *)deque)->maxlen); + result = PyUnicode_FromFormat("%s(%R, maxlen=%zd)", + _PyType_Name(Py_TYPE(deque)), aslist, + ((dequeobject *)deque)->maxlen); else - result = PyUnicode_FromFormat("deque(%R)", aslist); + result = PyUnicode_FromFormat("%s(%R)", + _PyType_Name(Py_TYPE(deque)), aslist); Py_ReprLeave(deque); Py_DECREF(aslist); return result; @@ -2127,7 +2129,8 @@ defdict_repr(defdictobject *dd) Py_DECREF(baserepr); return NULL; } - result = PyUnicode_FromFormat("defaultdict(%U, %U)", + result = PyUnicode_FromFormat("%s(%U, %U)", + _PyType_Name(Py_TYPE(dd)), defrepr, baserepr); Py_DECREF(defrepr); Py_DECREF(baserepr); diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 1d9a4f1..4f778a2 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -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; } diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 0e5cbbd..48e6c35 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -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 * |