Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11ade1d

Browse files
committed
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.
1 parent cf02ac6 commit 11ade1d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Lib/copy.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,24 @@ def deepcopy(x, memo = None):
164164
copierfunction = _deepcopy_dispatch[type(x)]
165165
except KeyError:
166166
try:
167-
copier = x.__deepcopy__
168-
except AttributeError:
167+
issc = issubclass(type(x), type)
168+
except TypeError:
169+
issc = 0
170+
if issc:
171+
y = _deepcopy_dispatch[type](x, memo)
172+
else:
169173
try:
170-
reductor = x.__reduce__
174+
copier = x.__deepcopy__
171175
except AttributeError:
172-
raise error, \
173-
"un-deep-copyable object of type %s" % type(x)
176+
try:
177+
reductor = x.__reduce__
178+
except AttributeError:
179+
raise error, \
180+
"un-deep-copyable object of type %s" % type(x)
181+
else:
182+
y = _reconstruct(x, reductor(), 1, memo)
174183
else:
175-
y = _reconstruct(x, reductor(), 1, memo)
176-
else:
177-
y = copier(memo)
184+
y = copier(memo)
178185
else:
179186
y = copierfunction(x, memo)
180187
memo[d] = y

0 commit comments

Comments
 (0)