[Python-checkins] CVS: python/dist/src/Lib copy.py,1.22,1.23
Guido van Rossum
gvanrossum@users.sourceforge.net
Fri, 28 Dec 2001 13:33:25 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv29054
Modified Files:
copy.py
Log Message:
Fix for SF bug ##497426: can't deepcopy recursive new objects
deepcopy(), _reconstruct(): pass the memo to the other function, so
that recursive data structures built out of new-style objects may be
deeply copied correctly.
2.2.1 bugfix!
Index: copy.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/copy.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** copy.py 2001/09/28 18:16:13 1.22
--- copy.py 2001/12/28 21:33:22 1.23
***************
*** 173,177 ****
"un-deep-copyable object of type %s" % type(x)
else:
! y = _reconstruct(x, reductor(), 1)
else:
y = copier(memo)
--- 173,177 ----
"un-deep-copyable object of type %s" % type(x)
else:
! y = _reconstruct(x, reductor(), 1, memo)
else:
y = copier(memo)
***************
*** 280,287 ****
d[types.InstanceType] = _deepcopy_inst
! def _reconstruct(x, info, deep):
if isinstance(info, str):
return x
assert isinstance(info, tuple)
n = len(info)
assert n in (2, 3)
--- 280,289 ----
d[types.InstanceType] = _deepcopy_inst
! def _reconstruct(x, info, deep, memo=None):
if isinstance(info, str):
return x
assert isinstance(info, tuple)
+ if memo is None:
+ memo = {}
n = len(info)
assert n in (2, 3)
***************
*** 292,300 ****
state = {}
if deep:
! args = deepcopy(args)
y = callable(*args)
if state:
if deep:
! state = deepcopy(state)
y.__dict__.update(state)
return y
--- 294,302 ----
state = {}
if deep:
! args = deepcopy(args, memo)
y = callable(*args)
if state:
if deep:
! state = deepcopy(state, memo)
y.__dict__.update(state)
return y