diff options
author | Guido van Rossum <guido@python.org> | 2002-06-10 21:10:27 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-06-10 21:10:27 (GMT) |
commit | 11ade1ddc053dcec884e2431b55fb1c1727c65d7 (patch) | |
tree | b418bbdd024c19b9a10269236c8fc80d36662d72 /Lib/copy.py | |
parent | cf02ac6154e30708379308f1a3206671e817165d (diff) | |
download | cpython-11ade1ddc053dcec884e2431b55fb1c1727c65d7.zip cpython-11ade1ddc053dcec884e2431b55fb1c1727c65d7.tar.gz cpython-11ade1ddc053dcec884e2431b55fb1c1727c65d7.tar.bz2 |
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'.
Bugfix candidate.
Diffstat (limited to 'Lib/copy.py')
-rw-r--r-- | Lib/copy.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/Lib/copy.py b/Lib/copy.py index 77b7ad3..7d06042 100644 --- a/Lib/copy.py +++ b/Lib/copy.py @@ -164,17 +164,24 @@ def deepcopy(x, memo = None): copierfunction = _deepcopy_dispatch[type(x)] except KeyError: try: - copier = x.__deepcopy__ - except AttributeError: + issc = issubclass(type(x), type) + except TypeError: + issc = 0 + if issc: + y = _deepcopy_dispatch[type](x, memo) + else: try: - reductor = x.__reduce__ + copier = x.__deepcopy__ except AttributeError: - raise error, \ - "un-deep-copyable object of type %s" % type(x) + 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 = _reconstruct(x, reductor(), 1, memo) - else: - y = copier(memo) + y = copier(memo) else: y = copierfunction(x, memo) memo[d] = y |