Remove dependency on anytree
TomNicholas opened this issue · comments
The code currently has a hard dependency on the anytree library, which it uses primarily to implement the actual .parent
& .children
structure of the TreeNode
class, through inheritance from anytree.NodeMixin
.
We don't need this dependency - anytree is not a big project, and we can simply reimplement the classes we need within this project instead. We should give due credit in the code because anytree has an Apache 2.0 license (plus Scout's honor).
Reimplementing anytree's functionality would also allow us to change various parts of it. For example we don't need support for python 2, we can standardize the error types (e.g. to return KeyError
instead of e.g. anytree.ResolverError
), and get rid of the mis-spelled .anchestors
property. We shouldn't need to worry about breaking the code because the tree functionality is already covered by the unit tests in test_treenode.py
.
I think that for the __slots__
defined in DatasetArithmetic
and other places in xarray to work then the whole chain of subclasses must define slots, but anytree.NodeMixin
does not define it. Unless we can monkey-patch __slots__
onto anytree.NodeMixin
then this would be another benefit of re-implementing NodeMixin ourselves.
Closed by #76