rename copy.Error to copy.error

This commit is contained in:
Guido van Rossum 1995-03-14 17:41:36 +00:00
parent 030afb1d3a
commit 55d2f3997e

View file

@ -9,7 +9,7 @@ Interface summary:
x = copy.copy(y) # make a shallow copy of y x = copy.copy(y) # make a shallow copy of y
x = copy.deepcopy(y) # make a deep copy of y x = copy.deepcopy(y) # make a deep copy of y
For module specific errors, copy.Error is raised. For module specific errors, copy.error is raised.
The difference between shallow and deep copying is only relevant for The difference between shallow and deep copying is only relevant for
compound objects (objects that contain other objects, like lists or compound objects (objects that contain other objects, like lists or
@ -52,7 +52,8 @@ __getstate__() and __setstate__(). See the __doc__ string of module
import types import types
Error = 'copy.Error' error = 'copy.error'
Error = error # backward compatibility
def copy(x): def copy(x):
"""Shallow copy operation on arbitrary Python objects. """Shallow copy operation on arbitrary Python objects.
@ -66,7 +67,7 @@ def copy(x):
try: try:
copier = x.__copy__ copier = x.__copy__
except AttributeError: except AttributeError:
raise Error, \ raise error, \
"un(shallow)copyable object of type %s" % type(x) "un(shallow)copyable object of type %s" % type(x)
y = copier() y = copier()
else: else:
@ -85,6 +86,7 @@ d[types.StringType] = _copy_atomic
d[types.CodeType] = _copy_atomic d[types.CodeType] = _copy_atomic
d[types.TypeType] = _copy_atomic d[types.TypeType] = _copy_atomic
d[types.XRangeType] = _copy_atomic d[types.XRangeType] = _copy_atomic
d[types.ClassType] = _copy_atomic
def _copy_list(x): def _copy_list(x):
return x[:] return x[:]
@ -140,7 +142,7 @@ def deepcopy(x, memo = None):
try: try:
copier = x.__deepcopy__ copier = x.__deepcopy__
except AttributeError: except AttributeError:
raise Error, \ raise error, \
"un-deep-copyable object of type %s" % type(x) "un-deep-copyable object of type %s" % type(x)
y = copier(memo) y = copier(memo)
else: else:
@ -220,7 +222,8 @@ del d
del types del types
def _test(): def _test():
l = [None, 1, 2L, 3.14, 'xyzzy', (1, 2L), [3.14, 'abc'], {'abc': 'ABC'}, (), [], {}] l = [None, 1, 2L, 3.14, 'xyzzy', (1, 2L), [3.14, 'abc'],
{'abc': 'ABC'}, (), [], {}]
l1 = copy(l) l1 = copy(l)
print l1==l print l1==l
l1 = map(copy, l) l1 = map(copy, l)