Commit 11ade1dd authored by Guido van Rossum's avatar Guido van Rossum

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.
parent cf02ac61
...@@ -164,17 +164,24 @@ def deepcopy(x, memo = None): ...@@ -164,17 +164,24 @@ def deepcopy(x, memo = None):
copierfunction = _deepcopy_dispatch[type(x)] copierfunction = _deepcopy_dispatch[type(x)]
except KeyError: except KeyError:
try: try:
copier = x.__deepcopy__ issc = issubclass(type(x), type)
except AttributeError: except TypeError:
issc = 0
if issc:
y = _deepcopy_dispatch[type](x, memo)
else:
try: try:
reductor = x.__reduce__ copier = x.__deepcopy__
except AttributeError: except AttributeError:
raise error, \ try:
"un-deep-copyable object of type %s" % type(x) reductor = x.__reduce__
except AttributeError:
raise error, \
"un-deep-copyable object of type %s" % type(x)
else:
y = _reconstruct(x, reductor(), 1, memo)
else: else:
y = _reconstruct(x, reductor(), 1, memo) y = copier(memo)
else:
y = copier(memo)
else: else:
y = copierfunction(x, memo) y = copierfunction(x, memo)
memo[d] = y memo[d] = y
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment