[Python-checkins] python/dist/src/Lib copy.py,1.22.10.3,1.22.10.4

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Mon, 10 Jun 2002 14:37:02 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv5115

Modified Files:
      Tag: release22-maint
	copy.py 
Log Message:
Backport:

SF patch 560794 (Greg Chapman): deepcopy can't handle custom
metaclasses.

This is essentially the same problem as that reported in bug 494904
for pickle: deepcopy should treat instances of custom metaclasses the
same way it treats instances of type 'type'.


Index: copy.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/copy.py,v
retrieving revision 1.22.10.3
retrieving revision 1.22.10.4
diff -C2 -d -r1.22.10.3 -r1.22.10.4
*** copy.py	6 Jun 2002 17:55:35 -0000	1.22.10.3
--- copy.py	10 Jun 2002 21:37:00 -0000	1.22.10.4
***************
*** 165,179 ****
      except KeyError:
          try:
!             copier = x.__deepcopy__
!         except AttributeError:
              try:
!                 reductor = x.__reduce__
              except AttributeError:
!                 raise error, \
!                       "un-deep-copyable object of type %s" % type(x)
              else:
!                 y = _reconstruct(x, reductor(), 1, memo)
!         else:
!             y = copier(memo)
      else:
          y = copierfunction(x, memo)
--- 165,186 ----
      except KeyError:
          try:
!             issc = issubclass(type(x), type)
!         except TypeError:
!             issc = 0
!         if issc:
!             y = _deepcopy_dispatch[type](x, memo)
!         else:
              try:
!                 copier = x.__deepcopy__
              except AttributeError:
!                 try:
!                     reductor = x.__reduce__
!                 except AttributeError:
!                     raise error, \
!                        "un-deep-copyable object of type %s" % type(x)
!                 else:
!                     y = _reconstruct(x, reductor(), 1, memo)
              else:
!                 y = copier(memo)
      else:
          y = copierfunction(x, memo)