This let us do inversion of control, passing in a callback function that gives more flexibility into how the node is rendered when using show() and save2file(). Essentially replaces the need for data_property - but we should probably keep it for backwards compatibility.
The callback function right now expect a string to be returned. I was thinking on maybe supporting None which could also replace the need for the filter argument: Return None to avoid the Node to be rendered. Let me know what you think @liamlundy or @caesar0301 :)
Example:
def render_node(node):
if node.is_leaf():
return node.my_property
return node.some_other_property
tree.show(render_node=render_node)
[x] I have formatted my code with Black I pass the local validation with scripts/flake8.sh.
[ ] I have updated docs: Please point me in the right direction here - I've added a docstring, but I'm not sure what/how/where to document the updated show() API.
This let us do inversion of control, passing in a callback function that gives more flexibility into how the node is rendered when using
show()
andsave2file()
. Essentially replaces the need fordata_property
- but we should probably keep it for backwards compatibility.The callback function right now expect a
string
to be returned. I was thinking on maybe supportingNone
which could also replace the need for thefilter
argument: ReturnNone
to avoid the Node to be rendered. Let me know what you think @liamlundy or @caesar0301 :)Example:
See unit test in 626f439 for an actual example.
Checklist
scripts/flake8.sh
.show()
API.