polymerist.genutils.trees.treebase ================================== .. py:module:: polymerist.genutils.trees.treebase .. autoapi-nested-parse:: Interfaces for encoding arbitrary classes into tree-like data structures Attributes ---------- .. autoapisummary:: polymerist.genutils.trees.treebase.T Classes ------- .. autoapisummary:: polymerist.genutils.trees.treebase.NodeCorrespondence Functions --------- .. autoapisummary:: polymerist.genutils.trees.treebase.compile_tree_factory Module Contents --------------- .. py:data:: T .. py:class:: NodeCorrespondence Bases: :py:obj:`abc.ABC`, :py:obj:`Generic`\ [\ :py:obj:`T`\ ] Abstract base for implementing how to build an anytree Node tree for an arbitrary class .. py:method:: name(obj: T) -> str :abstractmethod: Define how to obtain a string name .. py:method:: has_children(obj: T) -> bool :abstractmethod: Define how to check if an object can produce children in the first place before attempting to do so .. py:method:: children(obj: T) -> Optional[Iterable[T]] :abstractmethod: Define how to obtain node children from an instance Should return NoneType if the instance is "leaf-like" .. py:function:: compile_tree_factory(node_corresp: NodeCorrespondence[T], class_alias: Optional[str] = None, obj_attr_name: Optional[str] = None, exclude_mixin: Optional[polymerist.genutils.filters.Filter[T]] = None) -> Callable[[T, Optional[int], Optional[polymerist.genutils.filters.Filter[T]]], anytree.node.Node] Factory method for producing a tree-generating function from a NodeCorrespondence :Parameters: * **node_corresp** (*NodeCorrespondence[T]*) -- Definition of a correpondence between an arbitrary type and a Tree Node * **class_alias** (*str (optional)*) -- Name of the corresponding class to inject into docstring If not provided, will default to the __name__ of the class wrapped by node_corresp * **obj_attr_name** (*str (optional)*) -- The name of the Node attribute to which a copy of the class instance should be bound If not provided, will default to the value of class_alias * **exclude_mixin** (*Filter[T] (optional)*) -- An optional "master" filter to mix into any :returns: **compile_tree** -- Factory function which takes an instance of type T, builds a Tree from it, and returns the root Node :rtype: Callable[[T, Optional[int], Optional[Filter[T]]], Node]