| Jeff Abrahamson on 24 Oct 2004 21:02:03 -0000 |
|
I have a not very deep data structure. It just contains a dictionary
and some lists, nothing to scary. But when I try to deepcopy it, I
get bad errors (below).
I've googled and found a barely related bug reported only once, so I
don't really believe this is likely a python bug.
Anyone seen this before? Any thoughts?
>>> c=copy.deepcopy(b)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/copy.py", line 179, in deepcopy
y = copier(x, memo)
File "/usr/lib/python2.3/copy.py", line 307, in _deepcopy_inst
state = deepcopy(state, memo)
File "/usr/lib/python2.3/copy.py", line 179, in deepcopy
y = copier(x, memo)
File "/usr/lib/python2.3/copy.py", line 270, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.3/copy.py", line 179, in deepcopy
y = copier(x, memo)
File "/usr/lib/python2.3/copy.py", line 243, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/usr/lib/python2.3/copy.py", line 179, in deepcopy
y = copier(x, memo)
File "/usr/lib/python2.3/copy.py", line 243, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/usr/lib/python2.3/copy.py", line 206, in deepcopy
y = _reconstruct(x, rv, 1, memo)
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: function() takes at least 2 arguments (0 given)
>>>
Some of the structures to be copied are lists of lambda functions.
Here's something else that fails:
jeff@asterix:jeff $ python
Python 2.3.4 (#2, Jul 5 2004, 09:15:05)
[GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> b=[lambda x: x*x, lambda x: 2*x]
>>> import copy
>>> c=copy.copy(b)
>>> c
[<function <lambda> at 0x4021fd4c>, <function <lambda> at 0x4021fdbc>]
>>> c[0](3)
9
>>> c[1](3)
6
>>> d = copy.deepcopy(b)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/copy.py", line 179, in deepcopy
y = copier(x, memo)
File "/usr/lib/python2.3/copy.py", line 243, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/usr/lib/python2.3/copy.py", line 206, in deepcopy
y = _reconstruct(x, rv, 1, memo)
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: function() takes at least 2 arguments (0 given)
>>>
This doesn't seem right, though.
--
Jeff
Jeff Abrahamson <http://www.purple.com/jeff/> +1 215/837-2287
GPG fingerprint: 1A1A BA95 D082 A558 A276 63C6 16BF 8C4C 0D1D AE4B
A cool book of games, highly worth checking out:
http://www.amazon.com/exec/obidos/ASIN/1931686963/purple-20
Attachment:
signature.asc
|
|