From: Guido van Rossum Date: Mon, 10 Jun 2002 21:37:00 +0000 (+0000) Subject: Backport: X-Git-Tag: v2.2.2b1~335 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9396d834be5412dd28257c363cd1eec5269f2a40;p=thirdparty%2FPython%2Fcpython.git 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'. --- diff --git a/Lib/copy.py b/Lib/copy.py index bfe06e342dc6..1cb258c2f28f 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