caesar0301 / treelib

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

Implement public methods using private methods #159

Open 111pontes opened 4 years ago

111pontes commented 4 years ago

Overriding some of the current methods can have the nasty side effect of breaking other methods. Let me know if you'd consider having private version of methods used to implement other public methods. Something along the lines of:

def _is_leaf():  ## as currently implemented
    ...

def is_leaf():  ##  children can override without breaking leaves()
    return _is_leaf()

def leaves(self, nid=None):
    ...
            if node._is_leaf(self._identifier):
    ...

This change would be a great enhancement to make the tree more customizable and less likely to breakage. Not a theoretical exercise. Users are actually running into this type of situation. Happy to contribute 😎