[Python-checkins] r54760 - in python/trunk: Lib/test/test_slice.py Misc/NEWS Objects/sliceobject.c (original) (raw)

raymond.hettinger python-checkins at python.org
Wed Apr 11 20:41:02 CEST 2007


Author: raymond.hettinger Date: Wed Apr 11 20:40:58 2007 New Revision: 54760

Modified: python/trunk/Lib/test/test_slice.py python/trunk/Misc/NEWS python/trunk/Objects/sliceobject.c Log: SF 1191699: Make slices picklable

Modified: python/trunk/Lib/test/test_slice.py

--- python/trunk/Lib/test/test_slice.py (original) +++ python/trunk/Lib/test/test_slice.py Wed Apr 11 20:40:58 2007 @@ -2,6 +2,7 @@

import unittest from test import test_support +from cPickle import loads, dumps

import sys

@@ -102,6 +103,13 @@ x[1:2] = 42 self.assertEquals(tmp, [(1, 2, 42)])

def test_main(): test_support.run_unittest(SliceTest)

Modified: python/trunk/Misc/NEWS

--- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Wed Apr 11 20:40:58 2007 @@ -12,6 +12,8 @@ Core and builtins

+- Request #1191699: Slices can now be pickled. +

Modified: python/trunk/Objects/sliceobject.c

--- python/trunk/Objects/sliceobject.c (original) +++ python/trunk/Objects/sliceobject.c Wed Apr 11 20:40:58 2007 @@ -274,9 +274,19 @@ S. Out of bounds indices are clipped in a manner consistent with the\n
handling of normal slices."); +static PyObject * +slice_reduce(PySliceObject* self) +{ + return Py_BuildValue("O(OOO)", self->ob_type, self->start, self->stop, self->step); +} + +PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); + static PyMethodDef slice_methods[] = { {"indices", (PyCFunction)slice_indices, METH_O, slice_indices_doc}, + {"reduce", (PyCFunction)slice_reduce, + METH_NOARGS, reduce_doc}, {NULL, NULL} };


More information about the Python-checkins mailing list