]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
repr(range(10)) now returns 'range(0, 10)' for clarity.
authorWalter Dörwald <walter@livinglogic.de>
Mon, 21 May 2007 10:43:34 +0000 (10:43 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Mon, 21 May 2007 10:43:34 +0000 (10:43 +0000)
Lib/test/test_xrange.py
Objects/rangeobject.c

index a31f175a7f1a3a37cd0216238ebc8a701a02c443..3a5adf2b76052d6861f668568cce4ac92c0e7466 100644 (file)
@@ -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)')
 
index ad5d2fb3ac8b53c99deda29363df1028f333936a..4a45212dbe807fae571a24593f71e8909387f29b 100644 (file)
@@ -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)",