Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional support for subclassing of 'treelib.Node' #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RichardHoekstra
Copy link

In my own project I am extensively subclassing both 'treelib.Tree' and 'treelib.Node'. Using the 'data' variable, as mentioned in the documentation under advanced usage, does not work well for my use case.

It would make my life easier, and my code prettier, if I can pass additional arguments to Tree.create_node. The dependency injection is already there (self.node_class) and this PR should unlock more of the potential.

treelib/treelib/tree.py

Lines 339 to 346 in 017e891

def create_node(self, tag=None, identifier=None, parent=None, data=None):
"""
Create a child node for given @parent node. If ``identifier`` is absent,
a UUID will be generated automatically.
"""
node = self.node_class(tag=tag, identifier=identifier, data=data)
self.add_node(node, parent)
return node

… you are subclassing treelib.Node extensively and do not want to make use of the 'data' property of treelib.Node.

- Added a test case for the above mentioned 'kwargs'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant