betty.factory module¶
Functionality for creating new class instances.
- class betty.factory.Factory[source]¶
Bases:
ProtocolA callable to create a new instance.
- __init__(*args, **kwargs)¶
- exception betty.factory.FactoryError[source]¶
Bases:
RuntimeErrorRaised when a class could not be instantiated by a factory API.
- class betty.factory.IndependentFactory[source]¶
Bases:
ABCProvide a factory for classes that can instantiate themselves asynchronously.
- exception betty.factory.InitFactoryError[source]¶
Bases:
FactoryErrorRaised when a class could not be instantiated by calling it directly.
- class betty.factory.TargetFactory[source]¶
Bases:
ABCProvide a factory for classes that depend on
self.- abstract async new_target(cls: type[_T]) _T[source]¶
Create a new instance.
- Raises:
FactoryError – raised when
clscould not be instantiated.
- async betty.factory.new(cls: type[_T]) _T[source]¶
Create a new instance.
- Returns:
- If
clsextendsbetty.factory.IndependentFactory, this will call returncls’s new()’s return value.
- If
Otherwise
cls()will be called without arguments, and the resulting instance will be returned.
- Raises:
FactoryError – raised when
clscould not be instantiated.