mbrs.registry module#

class mbrs.registry.Registry(base_type: type[T])[source]#

Bases: dict[str, type[T]]

Registry that maps a name to its corresponding type.

get_closure() tuple[Callable[[str], Callable[[type[T]], type[T]]], Callable[[str], type[T]]][source]#

Get closure functions: register() and get_cls().

Returns:

  • Callable[[str], Callable[[type[T]], type[T]]]: register() function.

  • Callable[[str], type[T]]: get_cls() function.

Return type:

tuple

get_cls(name: str) type[T][source]#

Get a class type.

Parameters:

name – A registered name.

Returns:

Class type.

Return type:

type[T]

register(name: str) Callable[[type[T]], type[T]][source]#

Register a type as the given name.

Parameters:

name (str) – The name of a type.

Returns:

Register decorator function.

Return type:

Callable[[type[T]], type[T]]

Raises:

ValueError – The type is already registered.

mbrs.registry.get_registry(base_type: type[T]) Registry[T][source]#

Get registry of the given base class type.

Parameters:

base_type (type[T]) – Base class type that associated with the registry to be returned.

Returns:

Class mapper from registered name to its corresponding class.

Return type:

Registry[T]