From 667002ae109498bad217fd0ebcdf5af7c4a34ebb Mon Sep 17 00:00:00 2001 From: mozman Date: Sat, 29 Apr 2017 05:57:51 +0200 Subject: [PATCH] release v2.0.7 BUGFIX: foreach with empty tree raised exception close issue #3 --- NEWS.rst | 5 ++--- bintrees/abctree.py | 3 +++ setup.py | 2 +- tests/test_all_trees.py | 11 +++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index 2a42122..52f5cf1 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,10 +2,9 @@ NEWS ==== -bintrees development stopped, use `sortedcontainers` instead: https://pypi.python.org/pypi/sortedcontainers - -Version 2.0.7 - ... +Version 2.0.7 - 2017-04-28 + * BUGFIX: foreach (pure Python implementation) works with empty trees * acquire GIL for PyMem_Malloc() and PyMem_Free() calls Version 2.0.6 - 2017-02-04 diff --git a/bintrees/abctree.py b/bintrees/abctree.py index caf2669..87ba04b 100644 --- a/bintrees/abctree.py +++ b/bintrees/abctree.py @@ -644,6 +644,9 @@ def foreach(self, func, order=0): parm func: function(key, value) param int order: inorder = 0, preorder = -1, postorder = +1 """ + if self.count == 0: + return + def _traverse(node): if order == -1: func(node.key, node.value) diff --git a/setup.py b/setup.py index 28fdeba..479c400 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def read(fname): setup( name='bintrees', - version='2.0.6', + version='2.0.7', 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 09dcd6f..34169d5 100644 --- a/tests/test_all_trees.py +++ b/tests/test_all_trees.py @@ -868,6 +868,17 @@ def test_101_deepcopy_tree_in_tree(self): self.assertEqual(id(copytree21[5]), id(copytree22[5])) # sublist copied only once? self.assertEqual(id(copytree21[5]), id(copytree23[5])) # sublist copied only once? + def test_102_deepcopy_empty_tree(self): + tree1 = self.TREE_CLASS() + tree2 = deepcopy(tree1) + self.assertEqual(len(tree2), 0) + + def test_103_foreach_with_empty_tree(self): + tree1 = self.TREE_CLASS() + # does not raise any exception + tree1.foreach(lambda k, v: None) + self.assertTrue(True) + class TestBinaryTree(CheckTree, unittest.TestCase): TREE_CLASS = BinaryTree