caesar0301 / treelib

An efficient implementation of tree data structure in python 2/3.
http://treelib.readthedocs.io/en/latest/
Other
812 stars 186 forks source link

Cannot add root node after removing previous root #119

Closed tiagocoutinho closed 4 years ago

tiagocoutinho commented 5 years ago

expected behaviour

>>> t = treelib.Tree()
>>> t.create_node('bla', 'r0')
>>> print(len(t))
1
>>> print(t.root)
r0
>>> t.remove_node('r0')
>>> print(len(t))
0
>>> print(t.root)
None
>>> t.create_node('ble', 'r1')
>>> print(len(t))
1
>>> print(t.root)
r1

actual behaviour

>>> t = treelib.Tree()
>>> t.create_node('bla', 'r0')
>>> print(len(t))
1
>>> print(t.root)
r0
>>> t.remove_node('r0')
>>> print(len(t))
0
>>> print(t.root) # expected None here
r0
>>> t.create_node('ble', 'r1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/coutinho/workspace/treelib/treelib/tree.py", line 309, in create_node
    self.add_node(node, parent)
  File "/home/coutinho/workspace/treelib/treelib/tree.py", line 270, in add_node
    raise MultipleRootError("A tree takes one root merely.")
treelib.exceptions.MultipleRootError: A tree takes one root merely.
leonardbinet commented 4 years ago

fixed in #128 for 1.6.0 release