diff --git a/NEWS.rst b/NEWS.rst index 0e052cf..2afb8d3 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -4,6 +4,10 @@ NEWS bintrees development stopped, use `sortedcontainers` instead: https://pypi.python.org/pypi/sortedcontainers +Version 2.0.6 - 2017-02-04 + + * BUGFIX: correct deepcopy() for tree in tree + Version 2.0.5 - 2017-02-04 * support for copy.deepcopy() diff --git a/bintrees/abctree.py b/bintrees/abctree.py index d1b2bc5..caf2669 100644 --- a/bintrees/abctree.py +++ b/bintrees/abctree.py @@ -226,7 +226,7 @@ def copy(self): def __deepcopy__(self, memo): """copy.deepcopy(T) -> get a deep copy of T.""" def _deepcopy(key, value): - value_copy = deepcopy(value) + value_copy = deepcopy(value, memo) tree.insert(key, value_copy) tree = type(self)() diff --git a/setup.py b/setup.py index 9fe8db1..28fdeba 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def read(fname): setup( name='bintrees', - version='2.0.5', + version='2.0.6', description='Package provides Binary-, RedBlack- and AVL-Trees in Python and Cython.', author='mozman', url='https://github.com/mozman/bintrees.git', diff --git a/tests/test_all_trees.py b/tests/test_all_trees.py index 6c8eae6..09dcd6f 100644 --- a/tests/test_all_trees.py +++ b/tests/test_all_trees.py @@ -5,13 +5,12 @@ # Created: 28.04.2010 # Copyright (c) 2010-2017 by Manfred Moitzi # License: MIT License - import sys PYPY = hasattr(sys, 'pypy_version_info') import unittest import pickle - +from copy import deepcopy from random import randint, shuffle from bintrees import BinaryTree, AVLTree, RBTree, has_fast_tree_support @@ -799,7 +798,6 @@ def collect(key, value): self.assertEqual(list(tree.keys()), list(sorted(keys))) def test_099_deepcopy(self): - from copy import deepcopy data = { 2: 2, 3: 3, @@ -816,7 +814,6 @@ def test_099_deepcopy(self): self.assertEqual(tree[1][-1], 9) def test_100_deepcopy_tree_in_container(self): - from copy import deepcopy data = { 2: 2, 3: 3, @@ -841,6 +838,36 @@ def test_100_deepcopy_tree_in_container(self): self.assertTrue(17 in treecopy3) self.assertFalse(17 in tree) + def test_101_deepcopy_tree_in_tree(self): + data1 = { + 2: 2, + 3: 3, + 1: list(range(10)), + 4: 4, + 5: 5, + } + data2 = { + 7: 7, + 3: 3, + 5: list(range(10)), + 4: 4, + 9: 9, + } + tree1 = self.TREE_CLASS(data1) + tree2 = self.TREE_CLASS(data2) + tree1[6] = tree2 # 21 + tree1[8] = tree2 # 22 + tree1[1][5] = tree2 # 23 + copytree1 = deepcopy(tree1) + copytree21 = copytree1[6] + copytree22 = copytree1[8] + copytree23 = copytree1[1][5] + self.assertNotEqual(id(tree2), id(copytree21)) + self.assertEqual(id(copytree21), id(copytree22)) # copied only once? + self.assertEqual(id(copytree21), id(copytree23)) # tree in sublist, copied only once? + self.assertEqual(id(copytree21[5]), id(copytree22[5])) # sublist copied only once? + self.assertEqual(id(copytree21[5]), id(copytree23[5])) # sublist copied only once? + class TestBinaryTree(CheckTree, unittest.TestCase): TREE_CLASS = BinaryTree