betty.factory module¶
Functionality for creating new class instances.
- class betty.factory.Factory[source]¶
Bases:
Protocol
A callable to create a new instance.
- __init__(*args, **kwargs)¶
- exception betty.factory.FactoryError[source]¶
Bases:
RuntimeError
Raised when a class could not be instantiated by a factory API.
- class betty.factory.IndependentFactory[source]¶
Bases:
ABC
Provide a factory for classes that can instantiate themselves asynchronously.
- exception betty.factory.InitFactoryError[source]¶
Bases:
FactoryError
Raised when a class could not be instantiated by calling it directly.
- class betty.factory.TargetFactory[source]¶
Bases:
ABC
Provide 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
cls
could not be instantiated.
- async betty.factory.new(cls: type[_T]) _T [source]¶
Create a new instance.
- Returns:
- If
cls
extendsbetty.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
cls
could not be instantiated.