copy.deepcopy(instance) in jpython
jepler epler
jepler.lnk at lnk.ispi.net
Tue May 2 22:46:40 EDT 2000
This simple code runs in cpython and fails in jpython:
JPython 1.1 on java1.2.2 (JIT: sunwjit)
Copyright (C) 1997-1999 Corporation for National Research Initiatives
>>>import copy
>>>class X: pass
...
>>>x=X()
>>>y=copy.deepcopy(x)
Traceback (innermost last):
File "<console>", line 1, in ?
File "/usr/lib/python1.5/copy.py", line 151, in deepcopy
File "/usr/lib/python1.5/copy.py", line 236, in _deepcopy_inst
File "/usr/lib/python1.5/copy.py", line 147, in deepcopy
copy.error: un-deep-copyable object of type org.python.core.PyStringMap
I just checked "differences.html", and this isn't in there.
It seems that the problem is that copy.deepcopy doesn't understand
PyStringMap (A special version of dict with only strings for keys?) --
the following seems to fix it:
>>> type(x.__dict__)
<jclass org.python.core.PyStringMap at -2065579726>
>>> import org.python.core
>>> copy._deepcopy_dispatch[org.python.core.PyStringMap] = copy._deepcopy_dict
>>> copy.deepcopy(x)
<__main__.X instance at -1234058955>
Are there other types which will be pitfalls for copy.deepcopy()? Is my
jpython misinstalled and not picking up a jpythonifided copy module? Is
there some good way to make the same copy.py work for both C and JPython?
Jeff
More information about the Python-list
mailing list