Closed silvanocerza closed 1 year ago
Add from_dict and to_dict to Component interface.
from_dict
to_dict
Component
All classes decorated with @components will have a default implementation added.
@components
Given a MyComponent class that accepts a value parameter in __init__ to_dict() will create a dictionary similar to this:
MyComponent
value
__init__
to_dict()
{ "hash": <id_of_the_instance>, "type": "MyComponent", "init_parameters": { "value": 100 }, }
MyComponent.from_dict() will instead return a new instance of MyComponent given the above dictionary.
MyComponent.from_dict()
Trying to call OtherComponent.from_dict() using the above dictionary will fail.
OtherComponent.from_dict()
Add
from_dict
andto_dict
toComponent
interface.All classes decorated with
@components
will have a default implementation added.Given a
MyComponent
class that accepts avalue
parameter in__init__
to_dict()
will create a dictionary similar to this:MyComponent.from_dict()
will instead return a new instance ofMyComponent
given the above dictionary.Trying to call
OtherComponent.from_dict()
using the above dictionary will fail.