replace_with_canonical_aliases#
- treescope.handlers.replace_with_canonical_aliases(node: Any, path: str | None, node_renderer: renderers.TreescopeSubtreeRenderer, summarization_threshold: int = 20)[source]#
Rewrites objects to use well-known aliases when known.
This rendering hook checks if the object is a well-known object exported by a public API, and if so, makes its short representation be its path in that API rather than its repr.
Objects are looked up in canonical_aliases to determine if there is a specific alias registered for them. If not, but the object defines
__module__
and__qualname__
attributes, these are used to determine the canonical alias instead.For objects whose fully-qualified name is longer than
summarization_threshold
, we shorten it when collapsed or not in roundtrip mode.- Parameters:
node – The node that has been rendered
path – Optionally, a path to this node as a string.
node_renderer – The inner renderer for this node. This should be used to render
node
itself into HTML tags.summarization_threshold – Threshold at which to omit the fully-qualified name except in roundtrip mode.
- Returns:
A possibly-modified representation of this object, or NotImplemented.