SF bug #910986: copy.copy fails for array.array

Added support for the copy module.
This commit is contained in:
Raymond Hettinger 2004-03-13 18:18:51 +00:00
parent 42bec93e5c
commit 3aa82c07f7
3 changed files with 24 additions and 0 deletions

View File

@ -73,6 +73,13 @@ class BaseTest(unittest.TestCase):
b.byteswap() b.byteswap()
self.assertEqual(a, b) self.assertEqual(a, b)
def test_copy(self):
import copy
a = array.array(self.typecode, self.example)
b = copy.copy(a)
self.assertNotEqual(id(a), id(b))
self.assertEqual(a, b)
def test_insert(self): def test_insert(self):
a = array.array(self.typecode, self.example) a = array.array(self.typecode, self.example)
a.insert(0, self.example[0]) a.insert(0, self.example[0])

View File

@ -180,6 +180,8 @@ Core and builtins
Extension modules Extension modules
----------------- -----------------
- array objects now support the copy module
- cStringIO.writelines() now accepts any iterable argument and writes - cStringIO.writelines() now accepts any iterable argument and writes
the lines one at a time rather than joining them and writing once. the lines one at a time rather than joining them and writing once.
Made a parallel change to StringIO.writelines(). Saves memory and Made a parallel change to StringIO.writelines(). Saves memory and

View File

@ -616,6 +616,17 @@ array_slice(arrayobject *a, int ilow, int ihigh)
return (PyObject *)np; return (PyObject *)np;
} }
static PyObject *
array_copy(arrayobject *a, PyObject *unused)
{
return array_slice(a, 0, a->ob_size);
}
PyDoc_STRVAR(copy_doc,
"copy(array)\n\
\n\
Return a copy of the array.");
static PyObject * static PyObject *
array_concat(arrayobject *a, PyObject *bb) array_concat(arrayobject *a, PyObject *bb)
{ {
@ -1409,8 +1420,12 @@ PyMethodDef array_methods[] = {
buffer_info_doc}, buffer_info_doc},
{"byteswap", (PyCFunction)array_byteswap, METH_NOARGS, {"byteswap", (PyCFunction)array_byteswap, METH_NOARGS,
byteswap_doc}, byteswap_doc},
{"__copy__", (PyCFunction)array_copy, METH_NOARGS,
copy_doc},
{"count", (PyCFunction)array_count, METH_O, {"count", (PyCFunction)array_count, METH_O,
count_doc}, count_doc},
{"__deepcopy__",(PyCFunction)array_copy, METH_NOARGS,
copy_doc},
{"extend", (PyCFunction)array_extend, METH_O, {"extend", (PyCFunction)array_extend, METH_O,
extend_doc}, extend_doc},
{"fromfile", (PyCFunction)array_fromfile, METH_VARARGS, {"fromfile", (PyCFunction)array_fromfile, METH_VARARGS,