99 x = copy.copy(y) # make a shallow copy of y
1010 x = copy.deepcopy(y) # make a deep copy of y
1111
12- For module specific errors, copy.Error is raised.
12+ For module specific errors, copy.error is raised.
1313
1414The difference between shallow and deep copying is only relevant for
1515compound objects (objects that contain other objects, like lists or
@@ -52,7 +52,8 @@ class instances).
5252
5353import types
5454
55- Error = 'copy.Error'
55+ error = 'copy.error'
56+ Error = error # backward compatibility
5657
5758def copy (x ):
5859 """Shallow copy operation on arbitrary Python objects.
@@ -66,7 +67,7 @@ def copy(x):
6667 try :
6768 copier = x .__copy__
6869 except AttributeError :
69- raise Error , \
70+ raise error , \
7071 "un(shallow)copyable object of type %s" % type (x )
7172 y = copier ()
7273 else :
@@ -85,6 +86,7 @@ def _copy_atomic(x):
8586d [types .CodeType ] = _copy_atomic
8687d [types .TypeType ] = _copy_atomic
8788d [types .XRangeType ] = _copy_atomic
89+ d [types .ClassType ] = _copy_atomic
8890
8991def _copy_list (x ):
9092 return x [:]
@@ -140,7 +142,7 @@ def deepcopy(x, memo = None):
140142 try :
141143 copier = x .__deepcopy__
142144 except AttributeError :
143- raise Error , \
145+ raise error , \
144146 "un-deep-copyable object of type %s" % type (x )
145147 y = copier (memo )
146148 else :
@@ -220,7 +222,8 @@ def _deepcopy_inst(x, memo):
220222del types
221223
222224def _test ():
223- l = [None , 1 , 2L , 3.14 , 'xyzzy' , (1 , 2L ), [3.14 , 'abc' ], {'abc' : 'ABC' }, (), [], {}]
225+ l = [None , 1 , 2L , 3.14 , 'xyzzy' , (1 , 2L ), [3.14 , 'abc' ],
226+ {'abc' : 'ABC' }, (), [], {}]
224227 l1 = copy (l )
225228 print l1 == l
226229 l1 = map (copy , l )
0 commit comments