TreescopeNodeHandler#

class penzai.treescope.renderer.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: tuple[Any, ...] | 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. This will be the JAX keypath to the node if the node is part of a JAX PyTree. It may also be provided for nodes outside of the PyTree, in a format similar to that used by JAX keypaths. Handlers are encouraged to use this to build their rendering, and to pass an extended version when rendering their children using subtree_renderer.

  • 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.