hyped.core.registry.registry module

Type Register.

class hyped.core.registry.registry.RegisterMeta(name, bases, attrs, **kwargs)[source]

Bases: object

register type metaclass mixin.

property type_registry: RootedTypeRegistryView

Type Registry rooted at the current type.

class hyped.core.registry.registry.RegisterTypeMeta(name, bases, attrs, **kwargs)[source]

Bases: RegisterMeta, ABCMeta

Register type meta.

meta-class to automatically register sub-types of a specific type in a type registry.

class hyped.core.registry.registry.RegisterTypeMixin[source]

Bases: Registrable

Register Types.

Base class that automatically registers sub-types to the default type registry.

class hyped.core.registry.registry.Registrable[source]

Bases: ABC

Base Class for Registrable Types.

class property type_hash: str

Get type hash.

The computed hash-code is based on the source code of the type and not runtime specific. This allows for type resolving by hash accross python runtimes.

When the source code of the class is not available, the hash of the class module and name is computed instead. This is the case for pre-compiled classes or classes defined in jupyter notebooks.

Returns:

hash code of type

Return type:

h (str)

class property type_id: str | None

Type identifier.

If None, the type will not be registered.

class hyped.core.registry.registry.RootedTypeRegistryView(root: type, registry: TypeRegistry)[source]

Bases: object

Rooted Type Registry View.

Only has access to registered types that inherit the specified root.

property concrete_types: list[type]

List of all concrete (i.e. non-abstract) registered types.

get_type_by_hash(h: str) type[source]

Get registered type by type hash.

Parameters:

h (str) – type hash

Returns:

registered type corresponding to h

Return type:

T (type)

get_type_by_t(t: str) type[source]

Get registered type by type id.

Parameters:

t (int) – type identifier

Returns:

type corresponding to t

Return type:

T (type)

property hash_register: dict[str, str]

Hash Register.

Immutable hash register mapping type id to the corresponding type hash.

property type_ids: list[type]

List of all registered type identifiers.

property type_register: dict[str, type]

Type Register.

Immutable type register mapping type hash to the corresponding type.

property types: list[type]

List of all registered types.

class hyped.core.registry.registry.TypeRegistry[source]

Bases: object

Type Registry.

Stores registrable types and holds functionality to get all registered sub-types of a given root type.

Registrable types must inherit from the Registrable type.

get_hash_register(root: type) dict[str, str][source]

Get the hash register for sub-types of a given root type.

Parameters:

root (type) – root type

Returns:

the hash register mapping type identifiers to type hashes for types that inherit the root type

Return type:

hash_register (dict[str, str])

get_type_register(root: type) dict[str, type][source]

Get the type register for sub-types of a given root type.

Parameters:

root (type) – root type

Returns:

the type register mapping type hashes to types for types that inherit the root type

Return type:

type_register (dict[str, type])

global_hash_register: dict[str, str]
global_type_register: dict[str, type]
hash_tree: dict[str, list[str]]
hash_tree_bfs(root: str) Iterator[str][source]

Breadth-Frist Search through inheritance tree rooted at given type.

Parameters:

root (str) – hash of the root type

Returns:

iterator over all hashes of sub-types of the given root type

Return type:

node_iter (Iterator[str])

register_type(var: type, bases: tuple[type])[source]

Register a type.

Parameters:
  • var (type) – the type to register, must be a subclass of Registrable

  • bases (tuple[type]) – the base types of the type T

hyped.core.registry.registry.default_registry = <hyped.core.registry.registry.TypeRegistry object>

Default type registry tracking all registrable types