mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
cf02ac6154
commit
11ade1ddc0
1 changed files with 17 additions and 10 deletions
27
Lib/copy.py
27
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:
|
||||
try:
|
||||
reductor = x.__reduce__
|
||||
except AttributeError:
|
||||
raise error, \
|
||||
"un-deep-copyable object of type %s" % type(x)
|
||||
else:
|
||||
y = _reconstruct(x, reductor(), 1, memo)
|
||||
issc = issubclass(type(x), type)
|
||||
except TypeError:
|
||||
issc = 0
|
||||
if issc:
|
||||
y = _deepcopy_dispatch[type](x, memo)
|
||||
else:
|
||||
y = copier(memo)
|
||||
try:
|
||||
copier = x.__deepcopy__
|
||||
except AttributeError:
|
||||
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 = copier(memo)
|
||||
else:
|
||||
y = copierfunction(x, memo)
|
||||
memo[d] = y
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue