build_field_children

build_field_children#

treescope.rendering_parts.build_field_children(node: Any, path: str | None, subtree_renderer: renderers.TreescopeSubtreeRenderer, fields_or_attribute_names: Sequence[dataclasses.Field[Any] | str], 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.

  • 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 (with comma_separated=False)