Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (revision 45549) +++ Python/bltinmodule.c (working copy) @@ -1311,300 +1311,7 @@ equivalent to (x**y) % z, but may be more efficient (e.g. for longs)."); - -/* Return number of items in range (lo, hi, step), when arguments are - * PyInt or PyLong objects. step > 0 required. Return a value < 0 if - * & only if the true value is too large to fit in a signed long. - * Arguments MUST return 1 with either PyInt_Check() or - * PyLong_Check(). Return -1 when there is an error. - */ -static long -get_len_of_range_longs(PyObject *lo, PyObject *hi, PyObject *step) -{ - /* ------------------------------------------------------------- - Algorithm is equal to that of get_len_of_range(), but it operates - on PyObjects (which are assumed to be PyLong or PyInt objects). - ---------------------------------------------------------------*/ - long n; - PyObject *diff = NULL; - PyObject *one = NULL; - PyObject *tmp1 = NULL, *tmp2 = NULL, *tmp3 = NULL; - /* holds sub-expression evaluations */ - - /* if (lo >= hi), return length of 0. */ - if (PyObject_Compare(lo, hi) >= 0) - return 0; - - if ((one = PyLong_FromLong(1L)) == NULL) - goto Fail; - - if ((tmp1 = PyNumber_Subtract(hi, lo)) == NULL) - goto Fail; - - if ((diff = PyNumber_Subtract(tmp1, one)) == NULL) - goto Fail; - - if ((tmp2 = PyNumber_FloorDivide(diff, step)) == NULL) - goto Fail; - - if ((tmp3 = PyNumber_Add(tmp2, one)) == NULL) - goto Fail; - - n = PyLong_AsLong(tmp3); - if (PyErr_Occurred()) { /* Check for Overflow */ - PyErr_Clear(); - goto Fail; - } - - Py_DECREF(tmp3); - Py_DECREF(tmp2); - Py_DECREF(diff); - Py_DECREF(tmp1); - Py_DECREF(one); - return n; - - Fail: - Py_XDECREF(tmp3); - Py_XDECREF(tmp2); - Py_XDECREF(diff); - Py_XDECREF(tmp1); - Py_XDECREF(one); - return -1; -} - -/* An extension of builtin_range() that handles the case when PyLong - * arguments are given. */ static PyObject * -handle_range_longs(PyObject *self, PyObject *args) -{ - PyObject *ilow; - PyObject *ihigh = NULL; - PyObject *istep = NULL; - - PyObject *curnum = NULL; - PyObject *v = NULL; - long bign; - int i, n; - int cmp_result; - - PyObject *zero = PyLong_FromLong(0); - - if (zero == NULL) - return NULL; - - if (!PyArg_UnpackTuple(args, "range", 1, 3, &ilow, &ihigh, &istep)) { - Py_DECREF(zero); - return NULL; - } - - /* Figure out which way we were called, supply defaults, and be - * sure to incref everything so that the decrefs at the end - * are correct. - */ - assert(ilow != NULL); - if (ihigh == NULL) { - /* only 1 arg -- it's the upper limit */ - ihigh = ilow; - ilow = NULL; - } - assert(ihigh != NULL); - Py_INCREF(ihigh); - - /* ihigh correct now; do ilow */ - if (ilow == NULL) - ilow = zero; - Py_INCREF(ilow); - - /* ilow and ihigh correct now; do istep */ - if (istep == NULL) { - istep = PyLong_FromLong(1L); - if (istep == NULL) - goto Fail; - } - else { - Py_INCREF(istep); - } - - if (!PyInt_Check(ilow) && !PyLong_Check(ilow)) { - PyErr_Format(PyExc_TypeError, - "range() integer start argument expected, got %s.", - ilow->ob_type->tp_name); - goto Fail; - } - - if (!PyInt_Check(ihigh) && !PyLong_Check(ihigh)) { - PyErr_Format(PyExc_TypeError, - "range() integer end argument expected, got %s.", - ihigh->ob_type->tp_name); - goto Fail; - } - - if (!PyInt_Check(istep) && !PyLong_Check(istep)) { - PyErr_Format(PyExc_TypeError, - "range() integer step argument expected, got %s.", - istep->ob_type->tp_name); - goto Fail; - } - - if (PyObject_Cmp(istep, zero, &cmp_result) == -1) - goto Fail; - if (cmp_result == 0) { - PyErr_SetString(PyExc_ValueError, - "range() step argument must not be zero"); - goto Fail; - } - - if (cmp_result > 0) - bign = get_len_of_range_longs(ilow, ihigh, istep); - else { - PyObject *neg_istep = PyNumber_Negative(istep); - if (neg_istep == NULL) - goto Fail; - bign = get_len_of_range_longs(ihigh, ilow, neg_istep); - Py_DECREF(neg_istep); - } - - n = (int)bign; - if (bign < 0 || (long)n != bign) { - PyErr_SetString(PyExc_OverflowError, - "range() result has too many items"); - goto Fail; - } - - v = PyList_New(n); - if (v == NULL) - goto Fail; - - curnum = ilow; - Py_INCREF(curnum); - - for (i = 0; i < n; i++) { - PyObject *w = PyNumber_Long(curnum); - PyObject *tmp_num; - if (w == NULL) - goto Fail; - - PyList_SET_ITEM(v, i, w); - - tmp_num = PyNumber_Add(curnum, istep); - if (tmp_num == NULL) - goto Fail; - - Py_DECREF(curnum); - curnum = tmp_num; - } - Py_DECREF(ilow); - Py_DECREF(ihigh); - Py_DECREF(istep); - Py_DECREF(zero); - Py_DECREF(curnum); - return v; - - Fail: - Py_DECREF(ilow); - Py_DECREF(ihigh); - Py_XDECREF(istep); - Py_DECREF(zero); - Py_XDECREF(curnum); - Py_XDECREF(v); - return NULL; -} - -/* Return number of items in range/xrange (lo, hi, step). step > 0 - * required. Return a value < 0 if & only if the true value is too - * large to fit in a signed long. - */ -static long -get_len_of_range(long lo, long hi, long step) -{ - /* ------------------------------------------------------------- - If lo >= hi, the range is empty. - Else if n values are in the range, the last one is - lo + (n-1)*step, which must be <= hi-1. Rearranging, - n <= (hi - lo - 1)/step + 1, so taking the floor of the RHS gives - the proper value. Since lo < hi in this case, hi-lo-1 >= 0, so - the RHS is non-negative and so truncation is the same as the - floor. Letting M be the largest positive long, the worst case - for the RHS numerator is hi=M, lo=-M-1, and then - hi-lo-1 = M-(-M-1)-1 = 2*M. Therefore unsigned long has enough - precision to compute the RHS exactly. - ---------------------------------------------------------------*/ - long n = 0; - if (lo < hi) { - unsigned long uhi = (unsigned long)hi; - unsigned long ulo = (unsigned long)lo; - unsigned long diff = uhi - ulo - 1; - n = (long)(diff / (unsigned long)step + 1); - } - return n; -} - -static PyObject * -builtin_range(PyObject *self, PyObject *args) -{ - long ilow = 0, ihigh = 0, istep = 1; - long bign; - int i, n; - - PyObject *v; - - if (PyTuple_Size(args) <= 1) { - if (!PyArg_ParseTuple(args, - "l;range() requires 1-3 int arguments", - &ihigh)) { - PyErr_Clear(); - return handle_range_longs(self, args); - } - } - else { - if (!PyArg_ParseTuple(args, - "ll|l;range() requires 1-3 int arguments", - &ilow, &ihigh, &istep)) { - PyErr_Clear(); - return handle_range_longs(self, args); - } - } - if (istep == 0) { - PyErr_SetString(PyExc_ValueError, - "range() step argument must not be zero"); - return NULL; - } - if (istep > 0) - bign = get_len_of_range(ilow, ihigh, istep); - else - bign = get_len_of_range(ihigh, ilow, -istep); - n = (int)bign; - if (bign < 0 || (long)n != bign) { - PyErr_SetString(PyExc_OverflowError, - "range() result has too many items"); - return NULL; - } - v = PyList_New(n); - if (v == NULL) - return NULL; - for (i = 0; i < n; i++) { - PyObject *w = PyInt_FromLong(ilow); - if (w == NULL) { - Py_DECREF(v); - return NULL; - } - PyList_SET_ITEM(v, i, w); - ilow += istep; - } - return v; -} - -PyDoc_STRVAR(range_doc, -"range([start,] stop[, step]) -> list of integers\n\ -\n\ -Return a list containing an arithmetic progression of integers.\n\ -range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\n\ -When step is given, it specifies the increment (or decrement).\n\ -For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!\n\ -These are exactly the valid indices for a list of 4 elements."); - - -static PyObject * builtin_reduce(PyObject *self, PyObject *args) { PyObject *seq, *func, *result = NULL, *it; @@ -2075,7 +1782,6 @@ {"oct", builtin_oct, METH_O, oct_doc}, {"ord", builtin_ord, METH_O, ord_doc}, {"pow", builtin_pow, METH_VARARGS, pow_doc}, - {"range", builtin_range, METH_VARARGS, range_doc}, {"reduce", builtin_reduce, METH_VARARGS, reduce_doc}, {"reload", builtin_reload, METH_O, reload_doc}, {"repr", builtin_repr, METH_O, repr_doc}, @@ -2154,6 +1860,7 @@ SETBUILTIN("tuple", &PyTuple_Type); SETBUILTIN("type", &PyType_Type); SETBUILTIN("xrange", &PyRange_Type); + SETBUILTIN("range", &PyRange_Type); /* Note that open() is just an alias of file(). */ SETBUILTIN("open", &PyFile_Type); Index: Lib/stringprep.py =================================================================== --- Lib/stringprep.py (revision 45549) +++ Lib/stringprep.py (working copy) @@ -16,7 +16,7 @@ return (c & 0xFFFF) not in (0xFFFE, 0xFFFF) -b1_set = set([173, 847, 6150, 6155, 6156, 6157, 8203, 8204, 8205, 8288, 65279] + range(65024,65040)) +b1_set = set([173, 847, 6150, 6155, 6156, 6157, 8203, 8204, 8205, 8288, 65279] + list(range(65024,65040))) def in_table_b1(code): return ord(code) in b1_set @@ -217,7 +217,7 @@ def in_table_c21(code): return ord(code) < 128 and unicodedata.category(code) == "Cc" -c22_specials = set([1757, 1807, 6158, 8204, 8205, 8232, 8233, 65279] + range(8288,8292) + range(8298,8304) + range(65529,65533) + range(119155,119163)) +c22_specials = set([1757, 1807, 6158, 8204, 8205, 8232, 8233, 65279] + list(range(8288,8292)) + list(range(8298,8304)) + list(range(65529,65533)) + list(range(119155,119163))) def in_table_c22(code): c = ord(code) if c < 128: return False @@ -254,12 +254,12 @@ return ord(code) in c7_set -c8_set = set([832, 833, 8206, 8207] + range(8234,8239) + range(8298,8304)) +c8_set = set([832, 833, 8206, 8207] + list(range(8234,8239)) + list(range(8298,8304))) def in_table_c8(code): return ord(code) in c8_set -c9_set = set([917505] + range(917536,917632)) +c9_set = set([917505] + list(range(917536,917632))) def in_table_c9(code): return ord(code) in c9_set Index: Lib/mhlib.py =================================================================== --- Lib/mhlib.py (revision 45549) +++ Lib/mhlib.py (working copy) @@ -828,7 +828,7 @@ def tolist(self): l = [] for lo, hi in self.pairs: - m = range(lo, hi+1) + m = list(range(lo, hi+1)) l = l + m return l Index: Lib/doctest.py =================================================================== --- Lib/doctest.py (revision 45549) +++ Lib/doctest.py (working copy) @@ -2649,14 +2649,14 @@ "ellipsis": r""" If the ellipsis flag is used, then '...' can be used to elide substrings in the desired output: - >>> print range(1000) #doctest: +ELLIPSIS + >>> print list(range(1000)) #doctest: +ELLIPSIS [0, 1, 2, ..., 999] """, "whitespace normalization": r""" If the whitespace normalization flag is used, then differences in whitespace are ignored. - >>> print range(30) #doctest: +NORMALIZE_WHITESPACE + >>> print list(range(30)) #doctest: +NORMALIZE_WHITESPACE [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] Index: Lib/test/test_tuple.py =================================================================== --- Lib/test/test_tuple.py (revision 45549) +++ Lib/test/test_tuple.py (working copy) @@ -39,7 +39,7 @@ def f(): for i in range(1000): yield i - self.assertEqual(list(tuple(f())), range(1000)) + self.assertEqual(list(tuple(f())), list(range(1000))) def test_hash(self): # See SF bug 942952: Weakness in tuple hash @@ -58,7 +58,7 @@ # is sorely suspect. N=50 - base = range(N) + base = list(range(N)) xp = [(i, j) for i in base for j in base] inps = base + [(i, j) for i in base for j in xp] + \ [(i, j) for i in xp for j in base] + xp + zip(base) Index: Lib/test/test_set.py =================================================================== --- Lib/test/test_set.py (revision 45549) +++ Lib/test/test_set.py (working copy) @@ -471,7 +471,7 @@ self.assertEqual(id(self.s), id(dup)) def test_frozen_as_dictkey(self): - seq = range(10) + list('abcdefg') + ['apple'] + seq = list(range(10)) + list('abcdefg') + ['apple'] key1 = self.thetype(seq) key2 = self.thetype(reversed(seq)) self.assertEqual(key1, key2) Index: Lib/test/test_descr.py =================================================================== --- Lib/test/test_descr.py (revision 45549) +++ Lib/test/test_descr.py (working copy) @@ -2281,24 +2281,24 @@ class sublist(list): pass a = sublist(range(5)) - vereq(a, range(5)) + vereq(a, list(range(5))) a.append("hello") - vereq(a, range(5) + ["hello"]) + vereq(a, list(range(5)) + ["hello"]) a[5] = 5 - vereq(a, range(6)) + vereq(a, list(range(6))) a.extend(range(6, 20)) - vereq(a, range(20)) + vereq(a, list(range(20))) a[-5:] = [] - vereq(a, range(15)) + vereq(a, list(range(15))) del a[10:15] vereq(len(a), 10) - vereq(a, range(10)) - vereq(list(a), range(10)) + vereq(a, list(range(10))) + vereq(list(a), list(range(10))) vereq(a[0], 0) vereq(a[9], 9) vereq(a[-10], 0) vereq(a[-1], 9) - vereq(a[:5], range(5)) + vereq(a[:5], list(range(5))) class CountedInput(file): """Counts lines read by self.readline(). @@ -2330,7 +2330,7 @@ f.writelines(lines) f.close() f = CountedInput(TESTFN) - for (i, expected) in zip(range(1, 5) + [4], lines + 2 * [""]): + for (i, expected) in zip(list(range(1, 5)) + [4], lines + 2 * [""]): got = f.readline() vereq(expected, got) vereq(f.lineno, i) @@ -2357,7 +2357,7 @@ vereq(str(object=500), '500') vereq(unicode(string='abc', errors='strict'), u'abc') vereq(tuple(sequence=range(3)), (0, 1, 2)) - vereq(list(sequence=(0, 1, 2)), range(3)) + vereq(list(sequence=(0, 1, 2)), list(range(3))) # note: as of Python 2.3, dict() no longer has an "items" keyword arg for constructor in (int, float, long, complex, str, unicode, Index: Lib/test/test_bufio.py =================================================================== --- Lib/test/test_bufio.py (revision 45549) +++ Lib/test/test_bufio.py (working copy) @@ -48,8 +48,8 @@ nullpat = "\0" * 1000 try: - for size in range(1, 257) + [512, 1000, 1024, 2048, 4096, 8192, 10000, - 16384, 32768, 65536, 1000000]: + for size in list(range(1, 257)) + [512, 1000, 1024, 2048, 4096, 8192, + 10000, 16384, 32768, 65536, 1000000]: drive_one(primepat, size) drive_one(nullpat, size) finally: Index: Lib/test/test_generators.py =================================================================== --- Lib/test/test_generators.py (revision 45549) +++ Lib/test/test_generators.py (working copy) @@ -343,7 +343,7 @@ ... for c in gcomb(rest, k): ... yield c ->>> seq = range(1, 5) +>>> seq = list(range(1, 5)) >>> for k in range(len(seq) + 2): ... print "%d-combs of %s:" % (k, seq) ... for c in gcomb(seq, k): Index: Lib/test/test_fork1.py =================================================================== --- Lib/test/test_fork1.py (revision 45549) +++ Lib/test/test_fork1.py (working copy) @@ -44,7 +44,7 @@ a = alive.keys() a.sort() - verify(a == range(NUM_THREADS)) + verify(a == list(range(NUM_THREADS))) prefork_lives = alive.copy() Index: Lib/test/test_array.py =================================================================== --- Lib/test/test_array.py (revision 45549) +++ Lib/test/test_array.py (working copy) @@ -808,7 +808,7 @@ def test_iterationcontains(self): a = array.array(self.typecode, range(10)) - self.assertEqual(list(a), range(10)) + self.assertEqual(list(a), list(range(10))) b = array.array(self.typecode, [20]) self.assertEqual(a[-1] in a, True) self.assertEqual(b[0] not in a, True) Index: Lib/test/test_contains.py =================================================================== --- Lib/test/test_contains.py (revision 45549) +++ Lib/test/test_contains.py (working copy) @@ -86,7 +86,7 @@ check(unicode('d') not in 'abc', "u'd' in 'abc'") # A collection of tests on builtin sequence types -a = range(10) +a = list(range(10)) for i in a: check(i in a, "%r not in %r" % (i, a)) check(16 not in a, "16 not in %r" % (a,)) @@ -105,7 +105,7 @@ works when the list is modified during the check. """ - aList = range(15) + aList = list(range(15)) def __cmp__(self, other): if other == 12: Index: Lib/test/test_itertools.py =================================================================== --- Lib/test/test_itertools.py (revision 45549) +++ Lib/test/test_itertools.py (working copy) @@ -249,26 +249,28 @@ (10, 3), (20,) ]: - self.assertEqual(list(islice(xrange(100), *args)), range(*args)) + self.assertEqual(list(islice(xrange(100), *args)), + list(range(*args))) for args, tgtargs in [ # Stop when seqn is exhausted ((10, 110, 3), ((10, 100, 3))), ((10, 110), ((10, 100))), ((110,), (100,)) ]: - self.assertEqual(list(islice(xrange(100), *args)), range(*tgtargs)) + self.assertEqual(list(islice(xrange(100), *args)), + list(range(*tgtargs))) # Test stop=None - self.assertEqual(list(islice(xrange(10), None)), range(10)) - self.assertEqual(list(islice(xrange(10), None, None)), range(10)) - self.assertEqual(list(islice(xrange(10), None, None, None)), range(10)) - self.assertEqual(list(islice(xrange(10), 2, None)), range(2, 10)) - self.assertEqual(list(islice(xrange(10), 1, None, 2)), range(1, 10, 2)) + self.assertEqual(list(islice(xrange(10), None)), list(range(10))) + self.assertEqual(list(islice(xrange(10), None, None)), list(range(10))) + self.assertEqual(list(islice(xrange(10), None, None, None)), list(range(10))) + self.assertEqual(list(islice(xrange(10), 2, None)), list(range(2, 10))) + self.assertEqual(list(islice(xrange(10), 1, None, 2)), list(range(1, 10, 2))) # Test number of items consumed SF #1171417 it = iter(range(10)) - self.assertEqual(list(islice(it, 3)), range(3)) - self.assertEqual(list(it), range(3, 10)) + self.assertEqual(list(islice(it, 3)), list(range(3))) + self.assertEqual(list(it), list(range(3, 10))) # Test invalid arguments self.assertRaises(TypeError, islice, xrange(10)) @@ -323,20 +325,20 @@ self.assertEqual(zip(a,b), zip(range(n),range(n))) a, b = tee(irange(n)) # test 0% interleaved - self.assertEqual(list(a), range(n)) - self.assertEqual(list(b), range(n)) + self.assertEqual(list(a), list(range(n))) + self.assertEqual(list(b), list(range(n))) a, b = tee(irange(n)) # test dealloc of leading iterator for i in xrange(100): self.assertEqual(a.next(), i) del a - self.assertEqual(list(b), range(n)) + self.assertEqual(list(b), list(range(n))) a, b = tee(irange(n)) # test dealloc of trailing iterator for i in xrange(100): self.assertEqual(a.next(), i) del b - self.assertEqual(list(a), range(100, n)) + self.assertEqual(list(a), list(range(100, n))) for j in xrange(5): # test randomly interleaved order = [0]*n + [1]*n @@ -346,8 +348,8 @@ for i in order: value = its[i].next() lists[i].append(value) - self.assertEqual(lists[0], range(n)) - self.assertEqual(lists[1], range(n)) + self.assertEqual(lists[0], list(range(n))) + self.assertEqual(lists[1], list(range(n))) # test argument format checking self.assertRaises(TypeError, tee) @@ -364,10 +366,10 @@ a, b, c = tee(xrange(2000), 3) for i in xrange(100): self.assertEqual(a.next(), i) - self.assertEqual(list(b), range(2000)) - self.assertEqual([c.next(), c.next()], range(2)) - self.assertEqual(list(a), range(100,2000)) - self.assertEqual(list(c), range(2,2000)) + self.assertEqual(list(b), list(range(2000))) + self.assertEqual([c.next(), c.next()], list(range(2))) + self.assertEqual(list(a), list(range(100,2000))) + self.assertEqual(list(c), list(range(2,2000))) # test values of n self.assertRaises(TypeError, tee, 'abc', 'invalid') Index: Lib/test/test_unicode.py =================================================================== --- Lib/test/test_unicode.py (revision 45549) +++ Lib/test/test_unicode.py (working copy) @@ -659,7 +659,8 @@ # This excludes surrogates: in the full range, there would be # a surrogate pair (\udbff\udc00), which gets converted back # to a non-BMP character (\U0010fc00) - u = u''.join(map(unichr, range(0,0xd800)+range(0xe000,0x10000))) + u = u''.join(map(unichr, list(range(0,0xd800)) + + list(range(0xe000,0x10000)))) for encoding in ('utf-8',): self.assertEqual(unicode(u.encode(encoding),encoding), u) Index: Lib/test/test_pow.py =================================================================== --- Lib/test/test_pow.py (revision 45549) +++ Lib/test/test_pow.py (working copy) @@ -19,7 +19,7 @@ if i != 30 : pow2 = pow2*2 for othertype in int, long: - for i in range(-10, 0) + range(1, 10): + for i in list(range(-10, 0)) + list(range(1, 10)): ii = type(i) for j in range(1, 11): jj = -othertype(j) Index: Lib/test/test_gc.py =================================================================== --- Lib/test/test_gc.py (revision 45549) +++ Lib/test/test_gc.py (working copy) @@ -382,7 +382,7 @@ got = gc.get_referents([1, 2], {3: 4}, (0, 0, 0)) got.sort() - expect(got, [0, 0] + range(5), "get_referents") + expect(got, [0, 0] + list(range(5)), "get_referents") expect(gc.get_referents(1, 'a', 4j), [], "get_referents") Index: Lib/test/test_long.py =================================================================== --- Lib/test/test_long.py (revision 45549) +++ Lib/test/test_long.py (working copy) @@ -92,8 +92,8 @@ self.assert_(y < r <= 0, Frm("bad mod from divmod on %r and %r", x, y)) def test_division(self): - digits = range(1, MAXDIGITS+1) + range(KARATSUBA_CUTOFF, - KARATSUBA_CUTOFF + 14) + digits = list(range(1, MAXDIGITS+1)) + list(range(KARATSUBA_CUTOFF, + KARATSUBA_CUTOFF + 14)) digits.append(KARATSUBA_CUTOFF * 3) for lenx in digits: x = self.getran(lenx) @@ -102,7 +102,8 @@ self.check_division(x, y) def test_karatsuba(self): - digits = range(1, 5) + range(KARATSUBA_CUTOFF, KARATSUBA_CUTOFF + 10) + digits = list(range(1, 5)) + list(range(KARATSUBA_CUTOFF, + KARATSUBA_CUTOFF + 10)) digits.extend([KARATSUBA_CUTOFF * 10, KARATSUBA_CUTOFF * 100]) bits = [digit * SHIFT for digit in digits] @@ -382,7 +383,7 @@ LOG10E = math.log10(math.e) - for exp in range(10) + [100, 1000, 10000]: + for exp in list(range(10)) + [100, 1000, 10000]: value = 10 ** exp log10 = math.log10(value) self.assertAlmostEqual(log10, exp) Index: Lib/test/output/test_profile =================================================================== --- Lib/test/output/test_profile (revision 45549) +++ Lib/test/output/test_profile (working copy) @@ -1,5 +1,5 @@ test_profile - 127 function calls (107 primitive calls) in 1.000 CPU seconds + 119 function calls (99 primitive calls) in 1.000 CPU seconds Ordered by: standard name @@ -7,7 +7,6 @@ 4 0.000 0.000 0.000 0.000 :0(append) 4 0.000 0.000 0.000 0.000 :0(exc_info) 12 0.000 0.000 0.012 0.001 :0(hasattr) - 8 0.000 0.000 0.000 0.000 :0(range) 1 0.000 0.000 0.000 0.000 :0(setprofile) 1 0.000 0.000 1.000 1.000 :1() 0 0.000 0.000 profile:0(profiler) @@ -29,14 +28,12 @@ :0(append) -> :0(exc_info) -> :0(hasattr) -> test_profile.py:115(__getattr__)(12) 0.028 -:0(range) -> :0(setprofile) -> :1() -> test_profile.py:30(testfunc)(1) 1.000 profile:0(profiler) -> profile:0(testfunc())(1) 1.000 profile:0(testfunc()) -> :0(setprofile)(1) 0.000 :1()(1) 1.000 -test_profile.py:103(subhelper) -> :0(range)(8) 0.000 - test_profile.py:115(__getattr__)(16) 0.028 +test_profile.py:103(subhelper) -> test_profile.py:115(__getattr__)(16) 0.028 test_profile.py:115(__getattr__) -> test_profile.py:30(testfunc) -> test_profile.py:40(factorial)(1) 0.170 test_profile.py:60(helper)(2) 0.600 @@ -62,7 +59,6 @@ :0(exc_info) <- test_profile.py:78(helper1)(4) 0.120 :0(hasattr) <- test_profile.py:78(helper1)(4) 0.120 test_profile.py:93(helper2)(8) 0.400 -:0(range) <- test_profile.py:103(subhelper)(8) 0.080 :0(setprofile) <- profile:0(testfunc())(1) 1.000 :1() <- profile:0(testfunc())(1) 1.000 profile:0(profiler) <- Index: Lib/test/output/test_cProfile =================================================================== --- Lib/test/output/test_cProfile (revision 45549) +++ Lib/test/output/test_cProfile (working copy) @@ -1,5 +1,5 @@ test_cProfile - 126 function calls (106 primitive calls) in 1.000 CPU seconds + 118 function calls (98 primitive calls) in 1.000 CPU seconds Ordered by: standard name @@ -17,7 +17,6 @@ 12 0.000 0.000 0.012 0.001 {hasattr} 4 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} - 8 0.000 0.000 0.000 0.000 {range} 4 0.000 0.000 0.000 0.000 {sys.exc_info} @@ -27,7 +26,6 @@ ncalls tottime cumtime :1() -> 1 0.270 1.000 test_cProfile.py:30(testfunc) test_cProfile.py:103(subhelper) -> 16 0.016 0.016 test_cProfile.py:115(__getattr__) - 8 0.000 0.000 {range} test_cProfile.py:115(__getattr__) -> test_cProfile.py:30(testfunc) -> 1 0.014 0.130 test_cProfile.py:40(factorial) 2 0.040 0.600 test_cProfile.py:60(helper) @@ -47,7 +45,6 @@ {hasattr} -> 12 0.012 0.012 test_cProfile.py:115(__getattr__) {method 'append' of 'list' objects} -> {method 'disable' of '_lsprof.Profiler' objects} -> -{range} -> {sys.exc_info} -> @@ -73,7 +70,6 @@ 8 0.000 0.008 test_cProfile.py:93(helper2) {method 'append' of 'list' objects} <- 4 0.000 0.000 test_cProfile.py:78(helper1) {method 'disable' of '_lsprof.Profiler' objects} <- -{range} <- 8 0.000 0.000 test_cProfile.py:103(subhelper) {sys.exc_info} <- 4 0.000 0.000 test_cProfile.py:78(helper1) Index: Lib/test/test_doctest.py =================================================================== --- Lib/test/test_doctest.py (revision 45549) +++ Lib/test/test_doctest.py (working copy) @@ -1028,7 +1028,7 @@ (0, 1) An example from the docs: - >>> print range(20) #doctest: +NORMALIZE_WHITESPACE + >>> print list(range(20)) #doctest: +NORMALIZE_WHITESPACE [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] @@ -1036,7 +1036,7 @@ output to match any substring in the actual output: >>> def f(x): - ... '>>> print range(15)\n[0, 1, 2, ..., 14]\n' + ... '>>> print list(range(15))\n[0, 1, 2, ..., 14]\n' >>> # Without the flag: >>> test = doctest.DocTestFinder().find(f)[0] @@ -1045,7 +1045,7 @@ ********************************************************************** File ..., line 2, in f Failed example: - print range(15) + print list(range(15)) Expected: [0, 1, 2, ..., 14] Got: @@ -1072,11 +1072,11 @@ Examples from the docs: - >>> print range(20) # doctest:+ELLIPSIS + >>> print list(range(20)) # doctest:+ELLIPSIS [0, 1, ..., 18, 19] - >>> print range(20) # doctest: +ELLIPSIS - ... # doctest: +NORMALIZE_WHITESPACE + >>> print list(range(20)) # doctest: +ELLIPSIS + ... # doctest: +NORMALIZE_WHITESPACE [0, 1, ..., 18, 19] The REPORT_UDIFF flag causes failures that involve multi-line expected @@ -1291,10 +1291,10 @@ example with a comment of the form ``# doctest: +OPTION``: >>> def f(x): r''' - ... >>> print range(10) # should fail: no ellipsis + ... >>> print list(range(10)) # should fail: no ellipsis ... [0, 1, ..., 9] ... - ... >>> print range(10) # doctest: +ELLIPSIS + ... >>> print list(range(10)) # doctest: +ELLIPSIS ... [0, 1, ..., 9] ... ''' >>> test = doctest.DocTestFinder().find(f)[0] @@ -1303,7 +1303,7 @@ ********************************************************************** File ..., line 2, in f Failed example: - print range(10) # should fail: no ellipsis + print list(range(10)) # should fail: no ellipsis Expected: [0, 1, ..., 9] Got: @@ -1314,11 +1314,11 @@ comment of the form ``# doctest: -OPTION``: >>> def f(x): r''' - ... >>> print range(10) + ... >>> print list(range(10)) ... [0, 1, ..., 9] ... ... >>> # should fail: no ellipsis - ... >>> print range(10) # doctest: -ELLIPSIS + ... >>> print list(range(10)) # doctest: -ELLIPSIS ... [0, 1, ..., 9] ... ''' >>> test = doctest.DocTestFinder().find(f)[0] @@ -1328,7 +1328,7 @@ ********************************************************************** File ..., line 6, in f Failed example: - print range(10) # doctest: -ELLIPSIS + print list(range(10)) # doctest: -ELLIPSIS Expected: [0, 1, ..., 9] Got: @@ -1339,13 +1339,13 @@ do not change the options for surrounding examples: >>> def f(x): r''' - ... >>> print range(10) # Should fail: no ellipsis + ... >>> print list(range(10)) # Should fail: no ellipsis ... [0, 1, ..., 9] ... - ... >>> print range(10) # doctest: +ELLIPSIS + ... >>> print list(range(10)) # doctest: +ELLIPSIS ... [0, 1, ..., 9] ... - ... >>> print range(10) # Should fail: no ellipsis + ... >>> print list(range(10)) # Should fail: no ellipsis ... [0, 1, ..., 9] ... ''' >>> test = doctest.DocTestFinder().find(f)[0] @@ -1354,7 +1354,7 @@ ********************************************************************** File ..., line 2, in f Failed example: - print range(10) # Should fail: no ellipsis + print list(range(10)) # Should fail: no ellipsis Expected: [0, 1, ..., 9] Got: @@ -1362,7 +1362,7 @@ ********************************************************************** File ..., line 8, in f Failed example: - print range(10) # Should fail: no ellipsis + print list(range(10)) # Should fail: no ellipsis Expected: [0, 1, ..., 9] Got: @@ -1373,9 +1373,9 @@ may be separated by whitespace, commas, or both: >>> def f(x): r''' - ... >>> print range(10) # Should fail + ... >>> print list(range(10)) # Should fail ... [0, 1, ..., 9] - ... >>> print range(10) # Should succeed + ... >>> print list(range(10)) # Should succeed ... ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE ... [0, 1, ..., 9] ... ''' @@ -1385,7 +1385,7 @@ ********************************************************************** File ..., line 2, in f Failed example: - print range(10) # Should fail + print list(range(10)) # Should fail Expected: [0, 1, ..., 9] Got: @@ -1393,9 +1393,9 @@ (1, 2) >>> def f(x): r''' - ... >>> print range(10) # Should fail + ... >>> print list(range(10)) # Should fail ... [0, 1, ..., 9] - ... >>> print range(10) # Should succeed + ... >>> print list(range(10)) # Should succeed ... ... # doctest: +ELLIPSIS,+NORMALIZE_WHITESPACE ... [0, 1, ..., 9] ... ''' @@ -1405,7 +1405,7 @@ ********************************************************************** File ..., line 2, in f Failed example: - print range(10) # Should fail + print list(range(10)) # Should fail Expected: [0, 1, ..., 9] Got: @@ -1413,9 +1413,9 @@ (1, 2) >>> def f(x): r''' - ... >>> print range(10) # Should fail + ... >>> print list(range(10)) # Should fail ... [0, 1, ..., 9] - ... >>> print range(10) # Should succeed + ... >>> print list(range(10)) # Should succeed ... ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE ... [0, 1, ..., 9] ... ''' @@ -1425,7 +1425,7 @@ ********************************************************************** File ..., line 2, in f Failed example: - print range(10) # Should fail + print list(range(10)) # Should fail Expected: [0, 1, ..., 9] Got: @@ -1436,7 +1436,7 @@ long as a continuation prompt is used: >>> def f(x): r''' - ... >>> print range(10) + ... >>> print list(range(10)) ... ... # doctest: +ELLIPSIS ... [0, 1, ..., 9] ... ''' Index: Lib/test/test_sort.py =================================================================== --- Lib/test/test_sort.py (revision 45549) +++ Lib/test/test_sort.py (working copy) @@ -75,7 +75,7 @@ return "Stable(%d, %d)" % (self.key, self.index) for n in sizes: - x = range(n) + x = list(range(n)) if verbose: print "Testing size", n @@ -144,10 +144,10 @@ def test_cmpNone(self): # Testing None as a comparison function. - L = range(50) + L = list(range(50)) random.shuffle(L) L.sort(None) - self.assertEqual(L, range(50)) + self.assertEqual(L, list(range(50))) def test_undetected_mutation(self): # Python 2.4a1 did not always detect mutation @@ -204,31 +204,31 @@ def test_key_with_exception(self): # Verify that the wrapper has been removed - data = range(-2,2) + data = list(range(-2,2)) dup = data[:] self.assertRaises(ZeroDivisionError, data.sort, None, lambda x: 1/x) self.assertEqual(data, dup) def test_key_with_mutation(self): - data = range(10) + data = list(range(10)) def k(x): del data[:] - data[:] = range(20) + data[:] = list(range(20)) return x self.assertRaises(ValueError, data.sort, key=k) def test_key_with_mutating_del(self): - data = range(10) + data = list(range(10)) class SortKiller(object): def __init__(self, x): pass def __del__(self): del data[:] - data[:] = range(20) + data[:] = list(range(20)) self.assertRaises(ValueError, data.sort, key=SortKiller) def test_key_with_mutating_del_and_exception(self): - data = range(10) + data = list(range(10)) ## dup = data[:] class SortKiller(object): def __init__(self, x): @@ -236,7 +236,7 @@ raise RuntimeError def __del__(self): del data[:] - data[:] = range(20) + data[:] = list(range(20)) self.assertRaises(RuntimeError, data.sort, key=SortKiller) ## major honking subtlety: we *can't* do: ## @@ -248,10 +248,10 @@ ## date (this cost some brain cells to figure out...). def test_reverse(self): - data = range(100) + data = list(range(100)) random.shuffle(data) data.sort(reverse=True) - self.assertEqual(data, range(99,-1,-1)) + self.assertEqual(data, list(range(99,-1,-1))) self.assertRaises(TypeError, data.sort, "wrong type") def test_reverse_stability(self): Index: Lib/test/test_operator.py =================================================================== --- Lib/test/test_operator.py (revision 45549) +++ Lib/test/test_operator.py (working copy) @@ -138,7 +138,7 @@ self.assert_(a == [4, 2, 1]) def test_delslice(self): - a = range(10) + a = list(range(10)) self.failUnlessRaises(TypeError, operator.delslice, a) self.failUnlessRaises(TypeError, operator.delslice, a, None, None) self.failUnless(operator.delslice(a, 2, 8) is None) @@ -161,7 +161,7 @@ self.failUnless(operator.getitem(a, 2) == 2) def test_getslice(self): - a = range(10) + a = list(range(10)) self.failUnlessRaises(TypeError, operator.getslice) self.failUnlessRaises(TypeError, operator.getslice, a, None, None) self.failUnless(operator.getslice(a, 4, 6) == [4, 5]) @@ -258,7 +258,7 @@ self.assertRaises(TypeError, operator.pow, 1, 2, 3) def test_repeat(self): - a = range(3) + a = list(range(3)) self.failUnlessRaises(TypeError, operator.repeat) self.failUnlessRaises(TypeError, operator.repeat, a, None) self.failUnless(operator.repeat(a, 2) == a+a) @@ -298,7 +298,7 @@ self.failIf(operator.sequenceIncludes(range(4), 5)) def test_setitem(self): - a = range(3) + a = list(range(3)) self.failUnlessRaises(TypeError, operator.setitem, a) self.failUnlessRaises(TypeError, operator.setitem, a, None, None) self.failUnless(operator.setitem(a, 0, 2) is None) @@ -306,7 +306,7 @@ self.assertRaises(IndexError, operator.setitem, a, 4, 2) def test_setslice(self): - a = range(4) + a = list(range(4)) self.failUnlessRaises(TypeError, operator.setslice, a) self.failUnlessRaises(TypeError, operator.setslice, a, None, None, None) self.failUnless(operator.setslice(a, 1, 3, [2, 1]) is None) Index: Lib/test/pickletester.py =================================================================== --- Lib/test/pickletester.py (revision 45549) +++ Lib/test/pickletester.py (working copy) @@ -735,7 +735,7 @@ def test_list_chunking(self): n = 10 # too small to chunk - x = range(n) + x = list(range(n)) for proto in protocols: s = self.dumps(x, proto) y = self.loads(s) @@ -744,7 +744,7 @@ self.assertEqual(num_appends, proto > 0) n = 2500 # expect at least two chunks when proto > 0 - x = range(n) + x = list(range(n)) for proto in protocols: s = self.dumps(x, proto) y = self.loads(s) @@ -949,7 +949,7 @@ def test_persistence(self): self.id_count = 0 self.load_count = 0 - L = range(10) + L = list(range(10)) self.assertEqual(self.loads(self.dumps(L)), L) self.assertEqual(self.id_count, 5) self.assertEqual(self.load_count, 5) @@ -957,7 +957,7 @@ def test_bin_persistence(self): self.id_count = 0 self.load_count = 0 - L = range(10) + L = list(range(10)) self.assertEqual(self.loads(self.dumps(L, 1)), L) self.assertEqual(self.id_count, 5) self.assertEqual(self.load_count, 5) Index: Lib/test/test_pprint.py =================================================================== --- Lib/test/test_pprint.py (revision 45549) +++ Lib/test/test_pprint.py (working copy) @@ -28,8 +28,8 @@ class QueryTestCase(unittest.TestCase): def setUp(self): - self.a = range(100) - self.b = range(200) + self.a = list(range(100)) + self.b = list(range(200)) self.a[-12] = self.b def test_basic(self): Index: Lib/test/test_mhlib.py =================================================================== --- Lib/test/test_mhlib.py (revision 45549) +++ Lib/test/test_mhlib.py (working copy) @@ -121,7 +121,7 @@ 'Date': '29 July 2001'}, "Hullo, Mrs. Premise!\n") # A folder with many messages - for i in range(5, 101)+range(101, 201, 2): + for i in list(range(5, 101))+list(range(101, 201, 2)): writeMessage('wide', i, {'From': 'nowhere', 'Subject': 'message #%s' % i}, "This is message number %s\n" % i) @@ -203,7 +203,7 @@ f = mh.openfolder('wide') all = f.listmessages() - eq(all, range(5, 101)+range(101, 201, 2)) + eq(all, list(range(5, 101))+list(range(101, 201, 2))) eq(f.getcurrent(), 55) f.setcurrent(99) eq(readFile(os.path.join(_mhpath, 'wide', '.mh_sequences')), @@ -212,21 +212,21 @@ def seqeq(seq, val): eq(f.parsesequence(seq), val) - seqeq('5-55', range(5, 56)) - seqeq('90-108', range(90, 101)+range(101, 109, 2)) - seqeq('90-108', range(90, 101)+range(101, 109, 2)) + seqeq('5-55', list(range(5, 56))) + seqeq('90-108', list(range(90, 101))+list(range(101, 109, 2))) + seqeq('90-108', list(range(90, 101))+list(range(101, 109, 2))) - seqeq('10:10', range(10, 20)) - seqeq('10:+10', range(10, 20)) - seqeq('101:10', range(101, 121, 2)) + seqeq('10:10', list(range(10, 20))) + seqeq('10:+10', list(range(10, 20))) + seqeq('101:10', list(range(101, 121, 2))) seqeq('cur', [99]) seqeq('.', [99]) seqeq('prev', [98]) seqeq('next', [100]) seqeq('cur:-3', [97, 98, 99]) - seqeq('first-cur', range(5, 100)) - seqeq('150-last', range(151, 201, 2)) + seqeq('first-cur', list(range(5, 100))) + seqeq('150-last', list(range(151, 201, 2))) seqeq('prev-next', [98, 99, 100]) lowprimes = [5, 7, 11, 13, 17, 19, 23, 29] Index: Lib/test/test_iter.py =================================================================== --- Lib/test/test_iter.py (revision 45549) +++ Lib/test/test_iter.py (working copy) @@ -68,18 +68,18 @@ # Test basic use of iter() function def test_iter_basic(self): - self.check_iterator(iter(range(10)), range(10)) + self.check_iterator(iter(range(10)), list(range(10))) # Test that iter(iter(x)) is the same as iter(x) def test_iter_idempotency(self): - seq = range(10) + seq = list(range(10)) it = iter(seq) it2 = iter(it) self.assert_(it is it2) # Test that for loops over iterators work def test_iter_for_loop(self): - self.check_for_loop(iter(range(10)), range(10)) + self.check_for_loop(iter(range(10)), list(range(10))) # Test several independent iterators over the same list def test_iter_independence(self): @@ -106,19 +106,19 @@ # Test a class with __iter__ in a for loop def test_iter_class_for(self): - self.check_for_loop(IteratingSequenceClass(10), range(10)) + self.check_for_loop(IteratingSequenceClass(10), list(range(10))) # Test a class with __iter__ with explicit iter() def test_iter_class_iter(self): - self.check_iterator(iter(IteratingSequenceClass(10)), range(10)) + self.check_iterator(iter(IteratingSequenceClass(10)), list(range(10))) # Test for loop on a sequence class without __iter__ def test_seq_class_for(self): - self.check_for_loop(SequenceClass(10), range(10)) + self.check_for_loop(SequenceClass(10), list(range(10))) # Test iter() on a sequence class without __iter__ def test_seq_class_iter(self): - self.check_iterator(iter(SequenceClass(10)), range(10)) + self.check_iterator(iter(SequenceClass(10)), list(range(10))) # Test two-argument iter() with callable instance def test_iter_callable(self): @@ -131,7 +131,7 @@ if i > 100: raise IndexError # Emergency stop return i - self.check_iterator(iter(C(), 10), range(10)) + self.check_iterator(iter(C(), 10), list(range(10))) # Test two-argument iter() with function def test_iter_function(self): @@ -139,7 +139,7 @@ i = state[0] state[0] = i+1 return i - self.check_iterator(iter(spam, 10), range(10)) + self.check_iterator(iter(spam, 10), list(range(10))) # Test two-argument iter() with function that raises StopIteration def test_iter_function_stop(self): @@ -149,7 +149,7 @@ raise StopIteration state[0] = i+1 return i - self.check_iterator(iter(spam, 20), range(10)) + self.check_iterator(iter(spam, 20), list(range(10))) # Test exception propagation through function iterator def test_exception_function(self): @@ -164,7 +164,7 @@ for x in iter(spam, 20): res.append(x) except RuntimeError: - self.assertEqual(res, range(10)) + self.assertEqual(res, list(range(10))) else: self.fail("should have raised RuntimeError") @@ -180,7 +180,7 @@ for x in MySequenceClass(20): res.append(x) except RuntimeError: - self.assertEqual(res, range(10)) + self.assertEqual(res, list(range(10))) else: self.fail("should have raised RuntimeError") @@ -191,11 +191,11 @@ if i == 10: raise StopIteration return SequenceClass.__getitem__(self, i) - self.check_for_loop(MySequenceClass(20), range(10)) + self.check_for_loop(MySequenceClass(20), list(range(10))) # Test a big range def test_iter_big_range(self): - self.check_for_loop(iter(range(10000)), range(10000)) + self.check_for_loop(iter(range(10000)), list(range(10000))) # Test an empty list def test_iter_empty(self): @@ -203,11 +203,11 @@ # Test a tuple def test_iter_tuple(self): - self.check_for_loop(iter((0,1,2,3,4,5,6,7,8,9)), range(10)) + self.check_for_loop(iter((0,1,2,3,4,5,6,7,8,9)), list(range(10))) # Test an xrange def test_iter_xrange(self): - self.check_for_loop(iter(xrange(10)), range(10)) + self.check_for_loop(iter(xrange(10)), list(range(10))) # Test a string def test_iter_string(self): @@ -248,10 +248,9 @@ # Test list()'s use of iterators. def test_builtin_list(self): - self.assertEqual(list(SequenceClass(5)), range(5)) + self.assertEqual(list(SequenceClass(5)), list(range(5))) self.assertEqual(list(SequenceClass(0)), []) self.assertEqual(list(()), []) - self.assertEqual(list(range(10, -1, -1)), range(10, -1, -1)) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(list(d), d.keys()) @@ -313,7 +312,7 @@ # Test filter()'s use of iterators. def test_builtin_filter(self): - self.assertEqual(filter(None, SequenceClass(5)), range(1, 5)) + self.assertEqual(filter(None, SequenceClass(5)), list(range(1, 5))) self.assertEqual(filter(None, SequenceClass(0)), []) self.assertEqual(filter(None, ()), ()) self.assertEqual(filter(None, "abc"), "abc") @@ -389,8 +388,8 @@ # Test map()'s use of iterators. def test_builtin_map(self): - self.assertEqual(map(None, SequenceClass(5)), range(5)) - self.assertEqual(map(lambda x: x+1, SequenceClass(5)), range(1, 6)) + self.assertEqual(map(None, SequenceClass(5)), list(range(5))) + self.assertEqual(map(lambda x: x+1, SequenceClass(5)), list(range(1, 6))) d = {"one": 1, "two": 2, "three": 3} self.assertEqual(map(None, d), d.keys()) @@ -413,7 +412,7 @@ f.close() f = open(TESTFN, "r") try: - self.assertEqual(map(len, f), range(1, 21, 2)) + self.assertEqual(map(len, f), list(range(1, 21, 2))) finally: f.close() try: @@ -809,16 +808,16 @@ def test_sinkstate_list(self): # This used to fail - a = range(5) + a = list(range(5)) b = iter(a) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) a.extend(range(5, 10)) self.assertEqual(list(b), []) def test_sinkstate_tuple(self): a = (0, 1, 2, 3, 4) b = iter(a) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) self.assertEqual(list(b), []) def test_sinkstate_string(self): @@ -831,7 +830,7 @@ # This used to fail a = SequenceClass(5) b = iter(a) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) a.n = 10 self.assertEqual(list(b), []) @@ -844,7 +843,7 @@ raise AssertionError, "shouldn't have gotten this far" return i b = iter(spam, 5) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) self.assertEqual(list(b), []) def test_sinkstate_dict(self): @@ -861,13 +860,13 @@ for i in range(5): yield i b = gen() - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) self.assertEqual(list(b), []) def test_sinkstate_range(self): a = xrange(5) b = iter(a) - self.assertEqual(list(b), range(5)) + self.assertEqual(list(b), list(range(5))) self.assertEqual(list(b), []) def test_sinkstate_enumerate(self): Index: Lib/test/test_deque.py =================================================================== --- Lib/test/test_deque.py (revision 45549) +++ Lib/test/test_deque.py (working copy) @@ -33,19 +33,19 @@ d.__init__(xrange(100, 200)) for i in xrange(200, 400): d.append(i) - for i in reversed(xrange(-200, 0)): + for i in reversed(range(-200, 0)): d.appendleft(i) - self.assertEqual(list(d), range(-200, 400)) + self.assertEqual(list(d), list(range(-200, 400))) self.assertEqual(len(d), 600) left = [d.popleft() for i in xrange(250)] - self.assertEqual(left, range(-200, 50)) - self.assertEqual(list(d), range(50, 400)) + self.assertEqual(left, list(range(-200, 50))) + self.assertEqual(list(d), list(range(50, 400))) right = [d.pop() for i in xrange(250)] right.reverse() - self.assertEqual(right, range(150, 400)) - self.assertEqual(list(d), range(50, 150)) + self.assertEqual(right, list(range(150, 400))) + self.assertEqual(list(d), list(range(50, 150))) def test_comparisons(self): d = deque('xabc'); d.popleft() @@ -83,7 +83,7 @@ def test_getitem(self): n = 200 d = deque(xrange(n)) - l = range(n) + l = list(range(n)) for i in xrange(n): d.popleft() l.pop(0) @@ -269,7 +269,7 @@ x = pop() if x != i - size: self.assertEqual(x, i-size) - self.assertEqual(list(d), range(BIG-size, BIG)) + self.assertEqual(list(d), list(range(BIG-size, BIG))) def test_long_steadystate_queue_popright(self): for size in (0, 1, 2, 100, 1000): @@ -280,7 +280,8 @@ x = pop() if x != i - size: self.assertEqual(x, i-size) - self.assertEqual(list(reversed(list(d))), range(BIG-size, BIG)) + self.assertEqual(list(reversed(list(d))), + list(range(BIG-size, BIG))) def test_big_queue_popleft(self): pass @@ -412,17 +413,17 @@ d.append(i) for i in reversed(xrange(-200, 0)): d.appendleft(i) - self.assertEqual(list(d), range(-200, 400)) + self.assertEqual(list(d), list(range(-200, 400))) self.assertEqual(len(d), 600) left = [d.popleft() for i in xrange(250)] - self.assertEqual(left, range(-200, 50)) - self.assertEqual(list(d), range(50, 400)) + self.assertEqual(left, list(range(-200, 50))) + self.assertEqual(list(d), list(range(50, 400))) right = [d.pop() for i in xrange(250)] right.reverse() - self.assertEqual(right, range(150, 400)) - self.assertEqual(list(d), range(50, 150)) + self.assertEqual(right, list(range(150, 400))) + self.assertEqual(list(d), list(range(50, 150))) d.clear() self.assertEqual(len(d), 0) Index: Lib/test/test_tempfile.py =================================================================== --- Lib/test/test_tempfile.py (revision 45549) +++ Lib/test/test_tempfile.py (working copy) @@ -244,7 +244,7 @@ def test_basic_many(self): # _mkstemp_inner can create many files (stochastic) - extant = range(TEST_FILES) + extant = list(range(TEST_FILES)) for i in extant: extant[i] = self.do_create(pre="aa") @@ -456,7 +456,7 @@ def test_basic_many(self): # mkdtemp can create many directories (stochastic) - extant = range(TEST_FILES) + extant = list(range(TEST_FILES)) try: for i in extant: extant[i] = self.do_create(pre="aa") @@ -540,7 +540,7 @@ def test_many(self): # mktemp can choose many usable file names (stochastic) - extant = range(TEST_FILES) + extant = list(range(TEST_FILES)) for i in extant: extant[i] = self.do_create(pre="aa") Index: Lib/test/test_random.py =================================================================== --- Lib/test/test_random.py (revision 45549) +++ Lib/test/test_random.py (working copy) @@ -37,7 +37,7 @@ for arg in [None, 0, 0L, 1, 1L, -1, -1L, 10**20, -(10**20), 3.14, 1+2j, 'a', tuple('abc')]: self.gen.seed(arg) - for arg in [range(3), dict(one=1)]: + for arg in [list(range(3)), dict(one=1)]: self.assertRaises(TypeError, self.gen.seed, arg) self.assertRaises(TypeError, self.gen.seed, 1, 2) self.assertRaises(TypeError, type(self.gen), []) Index: Lib/test/test_slice.py =================================================================== --- Lib/test/test_slice.py (revision 45549) +++ Lib/test/test_slice.py (working copy) @@ -88,7 +88,7 @@ ) self.assertEqual(slice(-100L, 100L, 2L).indices(10), (0, 10, 2)) - self.assertEqual(range(10)[::sys.maxint - 1], [0]) + self.assertEqual(list(range(10))[::sys.maxint - 1], [0]) self.assertRaises(OverflowError, slice(None).indices, 1L<<100) Index: Lib/test/test_builtin.py =================================================================== --- Lib/test/test_builtin.py (revision 45549) +++ Lib/test/test_builtin.py (working copy) @@ -1182,52 +1182,18 @@ self.assertRaises(TypeError, pow) def test_range(self): - self.assertEqual(range(3), [0, 1, 2]) - self.assertEqual(range(1, 5), [1, 2, 3, 4]) - self.assertEqual(range(0), []) - self.assertEqual(range(-3), []) - self.assertEqual(range(1, 10, 3), [1, 4, 7]) - self.assertEqual(range(5, -5, -3), [5, 2, -1, -4]) + self.assertEqual(list(range(3)), [0, 1, 2]) + self.assertEqual(list(range(1, 5)), [1, 2, 3, 4]) + self.assertEqual(list(range(0)), []) + self.assertEqual(list(range(-3)), []) + self.assertEqual(list(range(1, 10, 3)), [1, 4, 7]) + self.assertEqual(list(range(5, -5, -3)), [5, 2, -1, -4]) - # Now test range() with longs - self.assertEqual(range(-2**100), []) - self.assertEqual(range(0, -2**100), []) - self.assertEqual(range(0, 2**100, -1), []) - self.assertEqual(range(0, 2**100, -1), []) - - a = long(10 * sys.maxint) - b = long(100 * sys.maxint) - c = long(50 * sys.maxint) - - self.assertEqual(range(a, a+2), [a, a+1]) - self.assertEqual(range(a+2, a, -1L), [a+2, a+1]) - self.assertEqual(range(a+4, a, -2), [a+4, a+2]) - - seq = range(a, b, c) - self.assert_(a in seq) - self.assert_(b not in seq) - self.assertEqual(len(seq), 2) - - seq = range(b, a, -c) - self.assert_(b in seq) - self.assert_(a not in seq) - self.assertEqual(len(seq), 2) - - seq = range(-a, -b, -c) - self.assert_(-a in seq) - self.assert_(-b not in seq) - self.assertEqual(len(seq), 2) - self.assertRaises(TypeError, range) self.assertRaises(TypeError, range, 1, 2, 3, 4) self.assertRaises(ValueError, range, 1, 2, 0) - self.assertRaises(ValueError, range, a, a + 1, long(0)) + self.assertRaises(ValueError, range, 1L, 2L, 0L) - class badzero(int): - def __cmp__(self, other): - raise RuntimeError - self.assertRaises(RuntimeError, range, a, a + 1, badzero(1)) - # Reject floats when it would require PyLongs to represent. # (smaller floats still accepted, but deprecated) self.assertRaises(TypeError, range, 1e100, 1e101, 1e101) @@ -1238,6 +1204,13 @@ self.assertRaises(OverflowError, range, -sys.maxint, sys.maxint) self.assertRaises(OverflowError, range, 0, 2*sys.maxint) + class badzero(int): + def __cmp__(self, other): + raise RuntimeError + def __eq__(self, other): + raise RuntimeError + self.assertRaises(RuntimeError, range, 1L, 2L, badzero(1)) + def test_reduce(self): self.assertEqual(reduce(lambda x, y: x+y, ['a', 'b', 'c'], ''), 'abc') self.assertEqual( @@ -1341,8 +1314,8 @@ def test_sum(self): self.assertEqual(sum([]), 0) - self.assertEqual(sum(range(2,8)), 27) - self.assertEqual(sum(iter(range(2,8))), 27) + self.assertEqual(sum(list(range(2,8))), 27) + self.assertEqual(sum(iter(list(range(2,8)))), 27) self.assertEqual(sum(Squares(10)), 285) self.assertEqual(sum(iter(Squares(10))), 285) self.assertEqual(sum([[1], [2], [3]], []), [1, 2, 3]) @@ -1454,7 +1427,7 @@ class TestSorted(unittest.TestCase): def test_basic(self): - data = range(100) + data = list(range(100)) copy = data[:] random.shuffle(copy) self.assertEqual(data, sorted(copy)) Index: Lib/test/test_multibytecodec_support.py =================================================================== --- Lib/test/test_multibytecodec_support.py (revision 45549) +++ Lib/test/test_multibytecodec_support.py (working copy) @@ -96,7 +96,7 @@ def test_streamreader(self): UTF8Writer = codecs.getwriter('utf-8') for name in ["read", "readline", "readlines"]: - for sizehint in [None, -1] + range(1, 33) + \ + for sizehint in [None, -1] + list(range(1, 33)) + \ [64, 128, 256, 512, 1024]: istream = self.reader(StringIO(self.tstring[0])) ostream = UTF8Writer(StringIO()) @@ -120,7 +120,7 @@ readfuncs = ('read',) UTF8Reader = codecs.getreader('utf-8') for name in readfuncs: - for sizehint in [None] + range(1, 33) + \ + for sizehint in [None] + list(range(1, 33)) + \ [64, 128, 256, 512, 1024]: istream = UTF8Reader(StringIO(self.tstring[1])) ostream = self.writer(StringIO())