TreescopeNodeHandler#

class treescope.renderers.TreescopeNodeHandler[source]#

Bases: Protocol

Protocol for a rendering handler for a particular node type.

Rendering handlers run in order (from most specific to least specific), until one of them is able to handle the given node. Handlers should return NotImplemented for types of node that they are unable to handle.

Methods

__init__(*args, **kwargs)

__call__(node, path, subtree_renderer)

Signature for a rendering handler for a particular node type.

__call__(node: Any, path: str | None, subtree_renderer: TreescopeSubtreeRenderer)[source]#

Signature for a rendering handler for a particular node type.

Parameters:
  • node – The node to render.

  • path – Optionally, a path to this node, represented as a string that can be used to reach this node from the root (e.g. “.foo.bar[‘baz’]”). Handlers should extend this path and pass it to subtree_renderer when rendering each of its children.

  • subtree_renderer – A recursive renderer for subtrees of this node. This should be used to render the children of this node into HTML tags to include in the rendering of this node. Should only be called on nodes that are children of node, to avoid an infinite loop.

Returns:

A representation of the object as a tree part, or NotImplemented if this handler doesn’t support rendering this object (indicating that we should try the next handler). Tree parts may have optional end-of-line annotations.