classification
Title: copy.copy fails for array.array
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: redandgray, rhettinger
Priority: normal Keywords:

Created on 2004-03-06 16:03 by redandgray, last changed 2004-03-13 18:28 by rhettinger. This issue is now closed.

Messages (2)
msg20177 - (view) Author: Glenn Parker (redandgray) Date: 2004-03-06 16:03
Python version 2.3.3 under WindowsXP Home Edition

The standard library "copy" does not work with the
standard library "array".

import copy
import array
x = array.array('c', 'abcdef')
y = copy.copy(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/copy.py", line 95, in copy
    return _reconstruct(x, rv, 0)
  File "/usr/lib/python2.3/copy.py", line 338, in
_reconstruct
    y = callable(*args)
  File "/usr/lib/python2.3/copy_reg.py", line 92, in
__newobj__
    return cls.__new__(cls, *args)
TypeError: array() takes at least 1 argument (0 given)

The same thing happens for copy.deepcopy.

Judging from the TypeError details, it appears that
copy.copy assumes a new object of the same type as its
input argument can be created with no arguments, but
array.array requires at least one argument (describing
the type of items in the array).

array.array should have a custom method added to make
it work smoothly with copy.copy.

Documentation for copy.copy should be clearer about the
requirements on the type of its input argument.
msg20178 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-03-13 18:28
Logged In: YES 
user_id=80475

Okay, added support for the copy module.

See Modules/arraymodule.c 2.93
History
Date User Action Args
2004-03-06 16:03:06redandgraycreate