handle_custom_mapping#
- treescope.repr_lib.handle_custom_mapping(node: Mapping[Any, Any], path: str | None, subtree_renderer: renderers.TreescopeSubtreeRenderer, *, roundtrippable: bool = False) rendering_parts.Rendering [source]#
Handler for custom mappings.
This wraps the
render_dictionary_wrapper
function so that it can be easily used as a type registry entry for custom mappings from third-party libraries. It assumes that the node itself is a mapping.For instance, if you know that third-party library type
SomeMapping
is a mapping, you can register a handler for it like this:treescope.type_registries.TREESCOPE_HANDLER_REGISTRY[SomeMapping] = ( treescope.repr_lib.handle_custom_mapping )
- Parameters:
node – The node to render.
path – The path to the node.
subtree_renderer – The renderer to use to render subtrees.
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
type(node)
takes a single argument, which is a dictionary, and thattype(node)
then acts like that dictionary.
- Returns:
A rendering of the node.