treescope.type_registries

treescope.type_registries#

Global registries for adding treescope support to external types.

This module defines global registries which can be used to add treescope support for new types that it does not natively support, or types defined in libraries that may not be installed.

These registries are intended to be used by either the module that defines the objects being registered, or by treescope itself. If a type already has a global registry entry, you should generally avoid modifying it. This is because the registries are defined as global variables, without a mechanism for resolving conflicts between multiple entries. If you would like to customize the rendering of a type that treescope already supports, you should generally either define your own treescope renderer object and use it directly, or override the default renderer or autovisualizer (treescope.active_renderer and treescope.active_autovisualizer) using the set_scoped and set_globally methods. This will take precedence over any global registry entries.

Functions

lookup_immutability_for_type(candidate_type)

Checks if an object is marked as immutable in the global registry.

lookup_ndarray_adapter(possible_array)

Looks up an NDArray adapter for the given type.

lookup_treescope_handler_for_type(candidate_type)

Looks up a treescope handler for the given type.

update_registries_for_imports()

Updates registries by running setup logic for newly-imported modules.

Module Attributes

NDARRAY_ADAPTER_REGISTRY

Global registry of NDArray adapters, keyed by type.

TREESCOPE_HANDLER_REGISTRY

Global registry of custom treescope handlers, keyed by type.

VIRTUAL_BASE_CLASSES

List of abstract base classes that should be checked for virtual subclasses.

IMMUTABLE_TYPES_REGISTRY

Global registry of non-hashable types that are considered immutable.