c0fec0de/anytree

Children order

Opened this issue · 2 comments

The current implementation does not provide the ability to rearrange the order of the children, which is used for instance in traversing the tree. I have not found a proper way to reorder children, without detaching and reattaching nodes, which causes all the __detach and __attach to be trigerred.

Would it be possible to improve the implementation to be able to work on the children list without triggering detach and attach, as long as the set(children) stay stable?

Things I would like to be able for instance includes: node.children = sorted(node.children, lambda node: node.weight), or alternatively sort(node.children).

Yes it is possible. I need to adapt the implementation. Not triggering the detach and attach hookups on a pure order change, is some kind of API change. Will think about it, but is not a big deal.