TreescopeCustomWrapperHook#
- class treescope.renderers.TreescopeCustomWrapperHook[source]#
Bases:
Protocol
Protocol for a custom wrapper hook.
Custom wrapper hooks are more powerful versions of node handlers. They run on every node, and are given control over how that node is rendered. In particular, they can modify the arguments that are passed to subsequent wrappers and ordinary handlers by calling
node_renderer
with modified values, and can also insert additional HTML tags around the rendered result.Generally, custom wrapper hooks should call
node_renderer
exactly once with the samenode
argument and the samepath
.Methods
__init__
(*args, **kwargs)__call__
(node, path, node_renderer)Signature for a custom wrapper hook.
- __call__(node: Any, path: str | None, node_renderer: TreescopeSubtreeRenderer)[source]#
Signature for a custom wrapper hook.
- Parameters:
node – The node that we are rendering.
path – Optionally, a path to this node as a string; see
TreescopeNodeHandler
.node_renderer – The inner renderer for this node. This can be used to render
node
itself according to the ordinary logic. Usually the wrapper hook should callnode_renderer
once withnode
, possibly customizing its arguments, and then postprocess the return value.
- Returns:
A modified rendering of the object, or NotImplemented if this hook does not want to modify this rendering at all. (Returning NotImplemented)