[Python-checkins] CVS: python/dist/src/Lib copy.py,1.22,1.22.10.1

Michael Hudson mwh@users.sourceforge.net
2002年1月04日 04:28:45 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv11184
Modified Files:
 Tag: release22-maint
	copy.py 
Log Message:
Backport gvanrossum's checkin of revisions 
 copy.py, 1.23 & test_descr.py, 1.114:
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.22.10.1
diff -C2 -d -r1.22 -r1.22.10.1
*** copy.py	2001年09月28日 18:16:13	1.22
--- copy.py	2002年01月04日 12:28:43	1.22.10.1
***************
*** 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

AltStyle によって変換されたページ (->オリジナル) /