render_list_wrapper#
- treescope.repr_lib.render_list_wrapper(object_type: type[Any], wrapped_sequence: Sequence[Any], path: str | None, subtree_renderer: renderers.TreescopeSubtreeRenderer, roundtrippable: bool = False, color: str | None = None) rendering_parts.Rendering[source]#
Renders an object in “wrapped list format”.
This produces a rendering like
Foo([1, 2, 3]), where Foo identifies the type of the object, and [1, 2, 3] is the list that Foo acts like. It is a requirement that these are accessible through__getitem__, e.g. asobj[0]or similar; otherwise, the path renderings will break.This can be used from within a
__treescope_repr__implementation viadef __treescope_repr__(self, path, subtree_renderer): return repr_lib.render_list_wrapper( object_type=type(self), wrapped_sequence=<sequence of items here>, path=path, subtree_renderer=subtree_renderer, )
- Parameters:
object_type – The type of the object.
wrapped_sequence – The sequence that the object wraps.
path – The path to the object. When
render_list_wrapperis called from__treescope_repr__, this should come from thepathargument to__treescope_repr__.subtree_renderer – The renderer to use to render subtrees. When
render_list_wrapperis called from__treescope_repr__, this should come from thesubtree_rendererargument to__treescope_repr__.roundtrippable – Whether evaluating the rendering as Python code will produce an object that is equal to the original object. This implies that the constructor for
object_typetakes a single argument, which is a sequence, and thatobject_typethen acts like that sequence.color – The background color to use for the object rendering. If None, does not use a background color. A utility for assigning a random color based on a string key is given in
treescope.formatting_util.
- Returns:
A rendering of the object, suitable for returning from
__treescope_repr__.