dacapo.store.conversion_hooks
Functions
|
Central place to register type hierarchies for conversion. |
|
Central place to register all conversion hooks with the given |
|
Convert a type string into the corresponding class. The class must be |
Module Contents
- dacapo.store.conversion_hooks.register_hierarchy_hooks(converter)
Central place to register type hierarchies for conversion.
- Parameters:
converter (Converter) – The converter to register the hooks with.
- Raises:
TypeError – If
clsis not a class.
Example
If class
Ais the base of classB, andconverter.register_hierarchy(A, lambda typ: eval(typ))has been called, the dictionaryy = converter.unstructure(x)will contain a__type__field that is'A'ifx = A()andBifx = B().This
__type__field is then used byx = converter.structure(y, A)to recreate the concrete type ofx.Note
This method is used to register a class hierarchy for typed structure/unstructure conversion. For each class in the hierarchy under (including)
cls, this will store an additional__type__attribute (a string) in the object dictionary. This__type__string will be the concrete class of the object, and will be used to structure the dictionary back into an object of the correct class.For this to work, this function needs to know how to convert a
__type__string back into a class, for which it used the providedcls_fn.
- dacapo.store.conversion_hooks.register_hooks(converter)
Central place to register all conversion hooks with the given converter.
- Parameters:
converter (Converter) – The converter to register the hooks with.
- Raises:
TypeError – If
clsis not a class.
Example
If class
Ais the base of classB, andconverter.register_hierarchy(A, lambda typ: eval(typ))has been called, the dictionaryy = converter.unstructure(x)will contain a__type__field that is'A'ifx = A()andBifx = B().This
__type__field is then used byx = converter.structure(y, A)to recreate the concrete type ofx.Note
This method is used to register a class hierarchy for typed structure/unstructure conversion. For each class in the hierarchy under (including)
cls, this will store an additional__type__attribute (a string) in the object dictionary. This__type__string will be the concrete class of the object, and will be used to structure the dictionary back into an object of the correct class.For this to work, this function needs to know how to convert a
__type__string back into a class, for which it used the providedcls_fn.
- dacapo.store.conversion_hooks.cls_fun(typ)
Convert a type string into the corresponding class. The class must be visible to this module (hence the star imports at the top).
- Parameters:
typ (str) – The type string to convert.
- Returns:
The class corresponding to the type string.
- Return type:
class
- Raises:
NameError – If the class is not visible to this module.
Example
cls_fun('TaskConfig')will return the classTaskConfig.Note
This function is used to convert a type string back into a class. It is used in conjunction with the
register_hierarchyfunction to register a class hierarchy for typed structure/unstructure conversion.