Abstract Factory API
sweet_tea.abstract_factory.AbstractFactory
Bases: Generic[T], Factory
A generic factory that constrains instantiation to subclasses of type T.
Usage
factory = AbstractFactory[MyBaseClass] instance = factory.create('my_key')
Only classes inheriting from MyBaseClass will be available
Source code in sweet_tea/abstract_factory.py
__class_getitem__(item)
classmethod
Create a parameterized generic subclass with the specified type.
Source code in sweet_tea/abstract_factory.py
create(key, library='', label='', configuration=None)
classmethod
Create an instance of a registered class that is a subclass of the generic type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Name to reference the class from the registry. |
required |
library
|
str
|
Optional library filter for the class. |
''
|
label
|
str
|
Optional label filter for the class. |
''
|
configuration
|
dict[str, Any] | None
|
Configuration parameters as keyword arguments. |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Configured instance of the requested class. |
Raises:
| Type | Description |
|---|---|
SweetTeaError
|
When the key is not found or filters don't match. |
Source code in sweet_tea/abstract_factory.py
Methods
create()
sweet_tea.abstract_factory.AbstractFactory.create(key, library='', label='', configuration=None)
classmethod
Create an instance of a registered class that is a subclass of the generic type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Name to reference the class from the registry. |
required |
library
|
str
|
Optional library filter for the class. |
''
|
label
|
str
|
Optional label filter for the class. |
''
|
configuration
|
dict[str, Any] | None
|
Configuration parameters as keyword arguments. |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Configured instance of the requested class. |
Raises:
| Type | Description |
|---|---|
SweetTeaError
|
When the key is not found or filters don't match. |