ModuleAttributeTree
ClassSource
ModuleAttributeTree(
walk_method: Callable[[str, dict[str, Any], list[T]], T], root_name: str = "."
)
The attribute tree of a module/package.
This tree reconstructs the member structure of a full package. It can be converted to a serialized dictionary/list.
Arguments
Requires
| Name | Type | Required | |
|---|---|---|---|
walk_method | Callable[[str, dict[str, Any], list[T]], T] | A method used to serialize tree nodes. The input arguments are:
The method will returns a serialized object representing the current node. | |
root_name | str | The name of the root node. |
Methods
add
self.add(node_full_name: str, node_attrs: Mapping[str, Any] | None = None)
Add a node to the attribute tree.
Requires
| Name | Type | Required | |
|---|---|---|---|
node_full_name | str | The full name like "package.module.member". | |
node_attrs | Mapping[str, Any] | None | An optional dictionary of attributes attached to the current added node. |
serialize
v_1: T = self.serialize()
Serialize the entire tree starting from root.
Returns
| Name | Type | |
|---|---|---|
v_1 | T | The serialized object of the root node, including all nested members. |
serialize_unpacked
v_1: list[T] = self.serialize_unpacked()
Serialize the entire tree starting from root, with the root node unpacked.
Different from self.serialize(), this method will treat the root node as a leaf node without members, and put all members of the root as siblings. Therefore, the returned value is always a list.
Returns
| Name | Type | |
|---|---|---|
v_1 | list[T] | The list of serialized nodes. |