Commit 03b43d8a authored by Walter Dörwald's avatar Walter Dörwald

repr(range(10)) now returns 'range(0, 10)' for clarity.

parent c2f6a58f
......@@ -57,7 +57,7 @@ class XrangeTest(unittest.TestCase):
self.assertEqual(len(r), sys.maxint)
def test_repr(self):
self.assertEqual(repr(range(1)), 'range(1)')
self.assertEqual(repr(range(1)), 'range(0, 1)')
self.assertEqual(repr(range(1, 2)), 'range(1, 2)')
self.assertEqual(repr(range(1, 2, 3)), 'range(1, 2, 3)')
......
......@@ -234,24 +234,17 @@ range_item(rangeobject *r, Py_ssize_t i)
static PyObject *
range_repr(rangeobject *r)
{
Py_ssize_t istart, istep;
Py_ssize_t istep;
/* Check for special case values for printing. We don't always
need the start or step values. We don't care about errors
need the step value. 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();
}
istep = PyNumber_AsSsize_t(r->step, NULL);
if (istep != 1 || (istep == -1 && PyErr_Occurred())) {
PyErr_Clear();
}
if (istart == 0 && istep == 1)
return PyUnicode_FromFormat("range(%R)", r->stop);
else if (istep == 1)
if (istep == 1)
return PyUnicode_FromFormat("range(%R, %R)", r->start, r->stop);
else
return PyUnicode_FromFormat("range(%R, %R, %R)",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment