spekk.trees.registry.TreeDef#
- class spekk.trees.registry.TreeDef(tree: Mapping[Any, Mapping[Any, Tree] | Sequence[Tree] | Any] | Sequence[Mapping[Any, Tree] | Sequence[Tree] | Any] | Any)[source]#
Bases:
ABCA
TreeDefis an abstraction for a tree-like data structure.We must be able to get the subtrees of the tree (keys and get) and create a copy with updated values (create). Anything that can support these operations can be used as a tree.
- __init__(tree: Mapping[Any, Mapping[Any, Tree] | Sequence[Tree] | Any] | Sequence[Mapping[Any, Tree] | Sequence[Tree] | Any] | Any)[source]#
Methods
__init__(tree)create(keys, values)Create a new instance of the tree with the given keys and values.
get(key)Get the subtree at the given key.
items()keys()Get the keys that can be used to get each subtree.
new_class(keys_fn, get_fn, create_fn)Helper function for creating a new
TreeDefclass.values()Get the subtrees for each key in the treedef.
- abstract create(keys: Sequence, values: Sequence) Mapping[Any, Mapping[Any, Tree] | Sequence[Tree] | Any] | Sequence[Mapping[Any, Tree] | Sequence[Tree] | Any] | Any[source]#
Create a new instance of the tree with the given keys and values.
>>> td = treedef({"a": 1, "b": 2}) >>> td.create(["a", "b"], [3, 4]) {'a': 3, 'b': 4}
- static new_class(keys_fn: Callable[[Mapping[Any, Mapping[Any, Tree] | Sequence[Tree] | Any] | Sequence[Mapping[Any, Tree] | Sequence[Tree] | Any] | Any], Sequence], get_fn: Callable[[Mapping[Any, Mapping[Any, Tree] | Sequence[Tree] | Any] | Sequence[Mapping[Any, Tree] | Sequence[Tree] | Any] | Any, Any], Any], create_fn: Callable[[Sequence, Sequence], Mapping[Any, Mapping[Any, Tree] | Sequence[Tree] | Any] | Sequence[Mapping[Any, Tree] | Sequence[Tree] | Any] | Any]) TreeDef[source]#
Helper function for creating a new
TreeDefclass.