Issue222859

classification
Title: copy.deepcopy(instance) fails in jpython
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: bckfnn
Priority: low Keywords:

Created on 2000-11-18.19:38:36 by bckfnn, last changed 2000-11-27.21:34:43 by bckfnn.

Messages
msg169 (view) Author: Finn Bock (bckfnn) Date: 2000-11-18.19:38:36
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()?
Finn@krause.dk writes:
> - Python instances which are subclasses of java instances.
>   The superclass isn't deepcopied.
> - The bug http://www.python.org/jpython-bugs/incoming?id=118
>   might also cause problems if your data structure have cycles.
msg170 (view) Author: Finn Bock (bckfnn) Date: 2000-11-27.21:34:43
Fixed by adding a slightlu modified version of CPython's copy module to jython.
History
Date User Action Args
2000-11-18 19:38:36bckfnncreate