build_field_children#
- penzai.treescope.handlers.builtin_structure_handler.build_field_children(node: dict[Any, Any], path: tuple[Any, ...] | None, subtree_renderer: renderer.TreescopeSubtreeRenderer, fields_or_attribute_names: Sequence[dataclasses.Field[Any] | str], key_path_fn: Callable[[str], Any] = <class 'jax._src.tree_util.GetAttrKey'>, attr_style_fn: Callable[[str], part_interface.RenderableTreePart] | None = None) list[part_interface.RenderableTreePart] [source]#
Renders a set of fields/attributes into a list of comma-separated children.
This is a helper function used for rendering dataclasses, namedtuples, and similar objects, of the form
ClassName( field_name_one=value1, field_name_two=value2, )
If
fields_or_attribute_names
includes dataclass fields:Metadata for the fields will be visible on hover,
Fields with
repr=False
will be hidden unless roundtrip mode is enabled.
- Parameters:
node – Node to render.
path – Path to this node.
subtree_renderer – How to render subtrees (see
TreescopeSubtreeRenderer
)fields_or_attribute_names – Sequence of fields or attribute names to render. Any field with the metadata key “treescope_always_collapse” set to True will always render collapsed.
key_path_fn – Optional function which maps field names to their JAX keys, if applicable. This should match their registered keypaths in the PyTree registry when applicable (although it will also be called for fields that are not necessarily PyTree children).
attr_style_fn – Optional function which makes attributes to a part that should render them. If not provided, all parts are rendered as plain text.
- Returns:
A list of child objects. This can be passed to
common_structures.build_foldable_tree_node_from_children
(withcomma_separated=False
)