Closed xiaohuihui1024 closed 4 years ago
Hi @xiaohuihui1024,
sorry, this part was (heavily) outdated. 'add_self' had been removed in August 2017 in 0.6.0
. If you want to initialize a machine without a model, you can pass model=None
or model=[]
. The default value for model
is 'self'
which will add the machine itself.
In addition, this part of the document mentions: [...]
I corrected that paragraph since the default value for initial='initial'
. It used to be initial=None
but added a state called 'initial' in that case as well. So, if you actually dont want an initial state you have to pass initial=None
explicitely.
from transitions import Machine
class Matter(object):
pass
machine = Machine(model=None, initial=None)
machine.add_model(Matter())
# >>> ValueError: No initial state configured for machine, must specify when adding model.
Thanks for your quick reply. @aleneum I have used "transition" since version 0.8.0 I don’t know some of the previous history. This issue seems to have been resolved, and users who read the document later will also avoid encountering this issue repeatedly.
This has been solved I guess. I will close this for now. Feel free to comment if this still is an issue. I will reopen it if necessary.
Hi, @aleneum Using: transitions 0.8.0+
The alternative-initialization-patterns section of the documentation has the following code:
The
add_self
parameter in the machine initialization parameters may be invalid, it will cause an errorI don’t quite understand how to use
add_self
correctlyIn addition, this part of the document mentions:
I can understand the meaning of the sample code, but in fact it does not work like the above code.
machine
has no an initial state (at least not specified in the initialization parameters).machine.add_model(Matter())
also did not specify an initial state forMatter()
It didn't occur the error in the document example, but it works normally.I try to verify what the initial state of the model is:
The result is as follows
I guess it should be added to the
initial
state by default