diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-06-27 21:22:46 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-06-27 21:22:46 (GMT) |
commit | e90ec366fb1f29705f3f6ed970091c5b3fa131a8 (patch) | |
tree | cfb0d7d582bdc169893a8530f2bfa25625d78bfd /Lib/test/test_copy.py | |
parent | 31877c9d0e4e005ef7faff45b4689358bd2aa93e (diff) | |
download | cpython-e90ec366fb1f29705f3f6ed970091c5b3fa131a8.zip cpython-e90ec366fb1f29705f3f6ed970091c5b3fa131a8.tar.gz cpython-e90ec366fb1f29705f3f6ed970091c5b3fa131a8.tar.bz2 |
don't memoize objects that are their own copies (closes #12422)
Patch mostly by Alex Gaynor.
Diffstat (limited to 'Lib/test/test_copy.py')
-rw-r--r-- | Lib/test/test_copy.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index a84c109..e450f70 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -321,9 +321,24 @@ class TestCopy(unittest.TestCase): def test_deepcopy_keepalive(self): memo = {} - x = 42 + x = [] + y = copy.deepcopy(x, memo) + self.assertIs(memo[id(memo)][0], x) + + def test_deepcopy_dont_memo_immutable(self): + memo = {} + x = [1, 2, 3, 4] y = copy.deepcopy(x, memo) - self.assertTrue(memo[id(x)] is x) + self.assertEqual(y, x) + # There's the entry for the new list, and the keep alive. + self.assertEqual(len(memo), 2) + + memo = {} + x = [(1, 2)] + y = copy.deepcopy(x, memo) + self.assertEqual(y, x) + # Tuples with immutable contents are immutable for deepcopy. + self.assertEqual(len(memo), 2) def test_deepcopy_inst_vanilla(self): class C: |