kayjan / bigtree

Tree Implementation and Methods for Python, integrated with list, dictionary, pandas and polars DataFrame.

Home Page:https://bigtree.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BaseNode.children is set as list, but get as tuple

lverweijen opened this issue · comments

It seems the children are set as a list, but are returned as a tuple.
I think it would make more sense to set/get it as the same type, probably a tuple.

It makes the following (no-op looking) code illegal:

node = Node("node")
node.children = node.children
# => TypeError: Children input should be list type, received input type <class 'tuple'>

It's risky too, because of the following:

root = Node("root")
mutable_children = list(map(Node, "abc"))

root.children = mutable_children
c = mutable_children.pop()

print(root.children)  # => (Node(/root/a, ), Node(/root/b, ))
print(c.parent)  # => Node(/root, )
raise ZeroDivisionError

Thanks for spotting this issue! I have modified children to take in Iterable which can accept lists and tuples (and other iterable types) in v0.9.5 (unreleased yet but it is in the v0.9.5 branch). Do check it out and see if there are any other issues if not v0.9.5 will be rolled out soon 😃

@kayjan Suggest to keep this and #67 and such issues open until the release has been made.

v0.9.5 is now live, do upgrade bigtree with pip install --upgrade bigtree to get the latest changes.