diff --git a/Lib/test/test_xrange.py b/Lib/test/test_xrange.py index a31f175a7f1..3a5adf2b760 100644 --- a/Lib/test/test_xrange.py +++ b/Lib/test/test_xrange.py @@ -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)') diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index ad5d2fb3ac8..4a45212dbe8 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -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)",