castlecraft_engineer.abstractions.translator
¶
castlecraft_engineer.abstractions.translator
¶
TranslationError
¶
Translator
¶
Bases: ABC
, Generic[Source, Target]
Abstract base class for a Translator. A Translator is responsible for converting an object of a source type to an object of a target type.
Source code in src/castlecraft_engineer/abstractions/translator.py
translate(source)
abstractmethod
¶
Translates a source object into a target object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Source
|
The object to translate. |
required |
Returns:
Type | Description |
---|---|
Target
|
The translated object of the target type. |
Raises:
Type | Description |
---|---|
TranslationError
|
If an error occurs during translation. |
Source code in src/castlecraft_engineer/abstractions/translator.py
translate_async(source)
async
¶
Asynchronously translates a source object into a target object. By default, this calls the synchronous translate method. Subclasses can override this for genuine async translation logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Source
|
The object to translate. |
required |
Returns:
Type | Description |
---|---|
Target
|
The translated object of the target type. |
Raises:
Type | Description |
---|---|
TranslationError
|
If an error occurs during translation. |