diff options
author | Walter Dörwald <walter@livinglogic.de> | 2007-05-20 08:19:54 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2007-05-20 08:19:54 (GMT) |
commit | 850e516ebc29187a200fecd7e325ea000f42043f (patch) | |
tree | 8bece8e588803426ca2fada5e961baea550a2b32 /Objects | |
parent | 7569dfe11d51a11bfb11002d31245b889916fb11 (diff) | |
download | cpython-850e516ebc29187a200fecd7e325ea000f42043f.zip cpython-850e516ebc29187a200fecd7e325ea000f42043f.tar.gz cpython-850e516ebc29187a200fecd7e325ea000f42043f.tar.bz2 |
Change range_repr() to use %R for the start/stop/step attributes.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/rangeobject.c | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index c5355df..ad5d2fb 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -234,52 +234,28 @@ range_item(rangeobject *r, Py_ssize_t i) static PyObject * range_repr(rangeobject *r) { - PyObject *start_str = NULL, *stop_str = NULL, *step_str = NULL; - PyObject *result = NULL; Py_ssize_t istart, istep; - /* We always need the stop value. */ - stop_str = PyObject_Str(r->stop); - if (!stop_str) - return NULL; - - /* XXX(nnorwitz): should we use PyObject_Repr instead of str? */ - /* Check for special case values for printing. We don't always need the start or step values. We don't care about errors (it means overflow), so clear the errors. */ istart = PyNumber_AsSsize_t(r->start, NULL); if (istart != 0 || (istart == -1 && PyErr_Occurred())) { PyErr_Clear(); - start_str = PyObject_Str(r->start); } istep = PyNumber_AsSsize_t(r->step, NULL); if (istep != 1 || (istep == -1 && PyErr_Occurred())) { PyErr_Clear(); - step_str = PyObject_Str(r->step); } if (istart == 0 && istep == 1) - result = PyUnicode_FromFormat("range(%s)", - PyString_AS_STRING(stop_str)); - else if (istep == 1) { - if (start_str) - result = PyUnicode_FromFormat("range(%s, %s)", - PyString_AS_STRING(start_str), - PyString_AS_STRING(stop_str)); - } - else if (start_str && step_str) - result = PyUnicode_FromFormat("range(%s, %s, %s)", - PyString_AS_STRING(start_str), - PyString_AS_STRING(stop_str), - PyString_AS_STRING(step_str)); - /* else result is NULL and an error should already be set. */ - - Py_XDECREF(start_str); - Py_XDECREF(stop_str); - Py_XDECREF(step_str); - return result; + return PyUnicode_FromFormat("range(%R)", r->stop); + else if (istep == 1) + return PyUnicode_FromFormat("range(%R, %R)", r->start, r->stop); + else + return PyUnicode_FromFormat("range(%R, %R, %R)", + r->start, r->stop, r->step); } static PySequenceMethods range_as_sequence = { |