Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Lib/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ def deepcopy(x, memo=None):
if memo is None:
memo = {}
else:
y = memo.get(d, None)
if y is not None:
return y
if d in memo:
return memo[d]

copier = _deepcopy_dispatch.get(cls)
if copier is not None:
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,17 @@ def m(self):
self.assertIs(g.b.__self__, g)
g.b()

def test_deepcopy_memo_none_result(self):
# Objects whose deepcopy result is None must still be memoized.
class C:
call_count = 0
def __deepcopy__(self, memo):
C.call_count += 1
return None
obj = C()
copy.deepcopy([obj, obj, obj])
self.assertEqual(C.call_count, 1)


class TestReplace(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`copy.deepcopy` so that an object whose deep copy is ``None`` is
still memoized. Patch by tonghuaroot.
Loading