ParametersWardrobe saving functions/objects
Raised by @meyer
ParametersWardrobe allows people to assign for example a function or other objects like Enum.
We can save the Wardrobe or export to beacon, but what is really exported is a reference to it.
Example:
TEST_SESSION [1]: from bliss.config.settings import ParametersWardrobe
TEST_SESSION [2]: A = ParametersWardrobe('A')
TEST_SESSION [28]: def f():
...: return True
TEST_SESSION [29]: A.add('method', f)
TEST_SESSION [30]: A
Out [30]: Parameters (default) -
.method = <function f at 0x7f6cbf8824d0>
.creation_date = '2020-02-18-17:27'
.last_accessed = '2020-02-18-17:27'
TEST_SESSION [34]: A.to_beacon('mysave','default')
In the saved file we have:
WardrobeName: A
instances:
default:
_creation_date: 2020-02-18-17:27
_last_accessed: 2020-02-18-17:30
method: !!python/name:__main__.f ''
In fact we store just a reference to the method and if we want to load back the settings we have before to
define the function f
that could be different from the original one.
BLISS [1]: from bliss.config.settings import ParametersWardrobe
BLISS [2]: A=ParametersWardrobe('A')
BLISS [3]: A
!!! === ValueError: parameters:A:default: Invalid value 'method` (cannot deserialize b'\x80\x03c__main__\nf\nq\x00.') === !!! ( for more details type cmd 'last_error' )
BLISS [4]: def f():
...: return False
BLISS [5]: A
Out [5]: Parameters (default) -
.method = <function f at 0x7f7a983c0ef0>
.creation_date = '2020-02-18-17:27'
.last_accessed = '2020-02-18-17:39'
What we really want from ParametersWardrobe?
- To store references with the assumption to recreate functions/objects in the setup script? (like it is now)
- To store complex object?
- To avoid assigning complex objects raising an Exception?