[Python-checkins] r64057 - in python/trunk: Lib/test/test_xrange.py Objects/rangeobject.c
alexandre.vassalotti
python-checkins at python.org
Tue Jun 10 05:34:54 CEST 2008
Author: alexandre.vassalotti
Date: Tue Jun 10 05:34:53 2008
New Revision: 64057
Log:
Issue 2582: Fix pickling of xrange objects.
Modified:
python/trunk/Lib/test/test_xrange.py
python/trunk/Objects/rangeobject.c
Modified: python/trunk/Lib/test/test_xrange.py
==============================================================================
--- python/trunk/Lib/test/test_xrange.py (original)
+++ python/trunk/Lib/test/test_xrange.py Tue Jun 10 05:34:53 2008
@@ -57,6 +57,16 @@
self.assertEqual(len(r), sys.maxint)
self.assertRaises(OverflowError, xrange, -sys.maxint-1, sys.maxint, 2)
+ def test_getnewargs(self):
+ def test(*args):
+ r = xrange(*args)
+ return list(r) == list(xrange(*r.__getnewargs__()))
+ tests = [(13,), (0, 11), (-22, 10), (20, 3, -1),
+ (13, 21, 3), (-2, 2, 2)]
+ for t in tests:
+ self.assert_(test(*t),
+ "xrange.__getnewargs__() failed with %r" % (t,))
+
def test_main():
test.test_support.run_unittest(XrangeTest)
Modified: python/trunk/Objects/rangeobject.c
==============================================================================
--- python/trunk/Objects/rangeobject.c (original)
+++ python/trunk/Objects/rangeobject.c Tue Jun 10 05:34:53 2008
@@ -129,6 +129,16 @@
return rtn;
}
+/* Pickling support */
+static PyObject *
+range_getnewargs(rangeobject *r)
+{
+ return Py_BuildValue("(iii)",
+ r->start,
+ r->start + r->len * r->step,
+ r->step);
+}
+
static PySequenceMethods range_as_sequence = {
(lenfunc)range_length, /* sq_length */
0, /* sq_concat */
@@ -145,6 +155,7 @@
static PyMethodDef range_methods[] = {
{"__reversed__", (PyCFunction)range_reverse, METH_NOARGS, reverse_doc},
+ {"__getnewargs__", (PyCFunction)range_getnewargs, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
More information about the Python-checkins
mailing list