Register Module

Declares decorators to register types or functions for a specific use.

Type register

Define decorators to register any type with a name in a dedicated register.

register_type(type_id: str) Callable[[T], T]

Class decorator to register the class type with the given name.

Parameters:

type_id (str) – the defined type id for the class type

Returns:

the class decorator

Return type:

Callable

get_registered_type(type_id: str) Any

Get a registered type.

Parameters:

type_id (str) – the registered type id

Returns:

the registered type

Return type:

type

get_registered_type_id(registered_type: type) Any

Get a registered type name for the matching type.

Parameters:

registered_type (type) – the registered type id

Returns:

the registered type id

Return type:

str

is_registered(key: Any) bool

Get if the given value is registered as a type or type id.

Parameters:

key (Any) – the key to test

Returns:

True if the key is registered, False otherwise

Return type:

bool

Load functions register

Define decorators to register any function as a specific load function of a configuration object.

loads(loaded_type: type[T]) Callable[[Callable[[...], T]], Callable[[...], T]]

Decorator to register a method that loads a registered type.

Parameters:

loaded_type (str) – the loaded type

Returns:

the class decorator

Return type:

Callable

get_load_function(loaded_type: type) Callable[[...], Any]

Get a registered load function.

Parameters:

type_id (str) – the registered type id

Raises:

KeyError – Raises a key error if the type is not registered.

Returns:

the registered type

Return type:

type

Save functions register

Define decorators to register any function as a specific save function of a configuration object.

saves(saved_type: type) Callable[[Callable[[...], Any]], Callable[[...], Any]]

Decorator to register a method that saves a registered type.

Parameters:

saved_type (str) – the saved type by the method

Returns:

the class decorator

Return type:

Callable

has_save_function(key: type) bool

Check if the type has a save function

Parameters:

key (Any) – the key to test

Returns:

True if the key is registered, False otherwise

Return type:

bool

get_save_function(saved_type: type) Callable[[...], Any]

Get a registered save function.

Parameters:

type_id (str) – the registered type id

Raises:

KeyError – Raises a key error if the type is not registered.

Returns:

the registered type

Return type:

type