medkit.core.dict_conv
medkit.core.dict_conv#
Classes:
|
Base protocol that must be implemented for all classes supporting conversion to a data dict and re-instantiation from a data dict. |
Base class for managing subclasses |
Functions:
|
Add a class name to a data dict returned by a to_dict() method, so we later know upon which class to call from_dict() when re-instantiating the corresponding object. |
|
Get the class name written in the data_dict by the to_dict method. |
- class DictConvertible(*args, **kwargs)[source]#
Base protocol that must be implemented for all classes supporting conversion to a data dict and re-instantiation from a data dict.
Methods:
from_dict
(data_dict)Re-instantiate an object from a datadict obtained via to_dict()
to_dict
()Convert current instance into a data dict that can later be used to rebuild the exact same instance
- class SubclassMapping[source]#
Base class for managing subclasses
Methods:
get_subclass_for_data_dict
(data_dict)Return the subclass that corresponds to the class name found in a data dict
- classmethod get_subclass_for_data_dict(data_dict)[source]#
Return the subclass that corresponds to the class name found in a data dict
- Parameters
data_dict (
Dict
[str
,Any
]) – Data dict returned by the to_dict() method of a subclass (or of the base class itself)- Return type
Optional
[Type
[Self
]]- Returns
subclass – Subclass that generated data_dict, or None if data_dict correspond to the base class itself.
- add_class_name_to_data_dict(instance, data_dict)[source]#
Add a class name to a data dict returned by a to_dict() method, so we later know upon which class to call from_dict() when re-instantiating the corresponding object.
- Parameters
instance (
object
) – The instance of class to which data_dict correspondsdata_dict (
Dict
[str
,Any
]) – The data dict on which to add the class name