Skip to content

Commit 2dfc60a

Browse files
committed
review comments
1 parent 4efeee3 commit 2dfc60a

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

Lib/copy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def deepcopy(x, memo=None):
166166
int, float, bool, complex, bytes, str, types.CodeType, type, range,
167167
types.BuiltinFunctionType, types.FunctionType, weakref.ref, property})
168168

169-
d = {}
169+
_deepcopy_dispatch = d = {}
170170

171171

172172
def _deepcopy_list(x, memo, deepcopy=deepcopy):
@@ -212,7 +212,6 @@ def _deepcopy_method(x, memo): # Copy instance methods
212212
return type(x)(x.__func__, deepcopy(x.__self__, memo))
213213
d[types.MethodType] = _deepcopy_method
214214

215-
_deepcopy_dispatch = frozendict(d)
216215
del d
217216

218217
def _keep_alive(x, memo):

Lib/test/test_descr.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,12 @@ def test_spam_lists(self):
311311
# Testing spamlist operations...
312312
import copy, xxsubtype as spam
313313

314-
spamlist = spam.spamlist
314+
def spamlist(l, memo=None):
315+
import xxsubtype as spam
316+
return spam.spamlist(l)
317+
318+
# This is an ugly hack:
319+
copy._deepcopy_dispatch[spam.spamlist] = spamlist
315320

316321
self.binop_test(spamlist([1]), spamlist([2]), spamlist([1,2]), "a+b",
317322
"__add__")
@@ -345,22 +350,19 @@ def foo(self): return 1
345350
a.setstate(42)
346351
self.assertEqual(a.getstate(), 42)
347352

348-
# test deepcopy makes a deep copy of the elements of a spamlist
349-
a.append([])
350-
a_copy = copy.deepcopy(a)
351-
assert a_copy is not a
352-
assert a_copy[-1] is not a[-1]
353-
assert a_copy == a
354-
# the spamlist does not explictly implement deepcopy, the state is not copied
355-
assert a_copy.getstate() != a.getstate()
356-
357353
@support.impl_detail("the module 'xxsubtype' is internal")
358354
@unittest.skipIf(xxsubtype is None, "requires xxsubtype module")
359355
def test_spam_dicts(self):
360356
# Testing spamdict operations...
361357
import copy, xxsubtype as spam
362-
363-
spamdict = spam.spamdict
358+
def spamdict(d, memo=None):
359+
import xxsubtype as spam
360+
sd = spam.spamdict()
361+
for k, v in list(d.items()):
362+
sd[k] = v
363+
return sd
364+
# This is an ugly hack:
365+
copy._deepcopy_dispatch[spam.spamdict] = spamdict
364366

365367
self.binop_test(spamdict({1:2,3:4}), 1, 1, "b in a", "__contains__")
366368
self.binop_test(spamdict({1:2,3:4}), 2, 0, "b in a", "__contains__")
@@ -399,15 +401,6 @@ def foo(self): return 1
399401
a.setstate(100)
400402
self.assertEqual(a.getstate(), 100)
401403

402-
# test deepcopy makes a deep copy of the elements of a spamdict
403-
a[-1] = []
404-
a_copy = copy.deepcopy(a)
405-
assert a_copy is not a
406-
assert a_copy[-1] is not a[-1]
407-
assert a_copy == a
408-
# the spamdict does not explictly implement deepcopy, the state is not copied
409-
assert a_copy.getstate() != a.getstate()
410-
411404
def test_wrap_lenfunc_bad_cast(self):
412405
self.assertEqual(range(sys.maxsize).__len__(), sys.maxsize)
413406

0 commit comments

Comments
 (0)