handle_structs#
- penzai.treescope.handlers.penzai.struct_handler.handle_structs(node: Any, path: tuple[Any, ...] | None, subtree_renderer: renderer.TreescopeSubtreeRenderer)[source]#
Renders a penzai struct or layer.
Differences in handling structs vs other dataclasses:
We use
cls.from_attributesinstead ofpenzai.util.dataclasses.dataclass_from_attributes(cls)for dataclasses with custom init logic.Colors are retrieved from the method
treescope_colorinstead of__treescope_color__.Keypaths are inferred using
key_for_field.Dataclass fields that are pytree children are rendered in a different style.
- Parameters:
node – The node to render.
path – Optionally, a path to this node.
subtree_renderer – A recursive renderer for subtrees of this node.
- Returns:
A rendering, or NotImplemented.