Closed jmorenobl closed 3 years ago
Hello @jmorenobl,
as far as I know it's not possible to pickle custom/dynamically created (instances of) classes. However,
this:
@add_state_features(MyState)
class MyMachine(Machine):
...
is just another way of writing:
class MyMachine(Machine):
state_cls = MyState
...
which -- as you pointed out -- can be pickled. If you need to combine multiple mixins, you can do it the same way:
class MyState(Error, Timeout, NestedState):
pass
class MyMachine(HierarchicalMachine):
state_cls = MyState
First, thank you for pointing this limitation/drawback out.
In https://github.com/pytransitions/transitions/commit/620526dba50963045cc51970fe49d7fe1eb049cd, I added a remark to the README about this. I hope this make this limitation more obvious. Right now I'd say there is not much I can do here. Especially since the workaround is not too complex/cluttered. I will close this issue for now. If you have further ideas/suggestions about how to improve @add_state_features
, let me know. I will reopen the issue if necessary.
Hello @aleneum ! thank you very much for your response and the great work with this library which is awesome!. I think is clear what is happening and the mention to the limitation is fair enough. The workaround is pretty easy and makes it perfectly viable to have both functionalities: adding state features through mixins and pickling.
Thanks, @jmorenobl.
I really appreciate that you came back to comment this :).
Basically this doesn't work:
This is the error:
I think it's related to the class CustomState not being in the root of the module. I have worked around it by doing the following: