betty.factory module#

Object factories.

class betty.factory.DataManufacturable#

Bases: ABC, Generic

A class that can be initialized using defined data.

abstractmethod async classmethod new(services: ServiceLevel, data: DataT, /) Self#

Create a new instance using the given service level and defined data.

abstractmethod classmethod new_data_cls() type[DataT]#

The object’s defined data class.

final class betty.factory.Factory#

Bases: object

The object factory.

__init__(services: ServiceLevel, /)#
async new(target: type[ManufacturableT], /) ManufacturableT#
async new(target: Manufacturer[T], /) T

Create a new instance.

Raises:

FactoryError – raised when target could not be called.

exception betty.factory.FactoryError#

Bases: RuntimeError

Raised when a factory could not create an object.

class betty.factory.Manufacturable#

Bases: ABC

Allow this type to be instantiated using a betty.service_level.ServiceLevel.

abstractmethod async classmethod new(services: ServiceLevel, /) Self#

Create a new instance using the given service level.

exception betty.factory.UnsupportedTarget#

Bases: FactoryError

Raised when a factory target cannot be used to create a new object.