2022-12-21
StateMachine 0.9 supports Python 2.7, 3.5, 3.6, 3.7, 3.8.
Parameters sent with the event trigger will now be propagated to the transition handlers.
>>> from statemachine import StateMachine, State
>>> class CampaignMachine(StateMachine):
... draft = State("Draft", initial=True)
... producing = State("Being produced")
...
... produce = draft.to(producing) | producing.to(producing)
...
... def on_enter_producing(self, approver=None):
... print("Approved by: {}".format(approver))
>>> sm = CampaignMachine()
>>> sm.produce(approver="Aragorn") # imperatite
Approved by: Aragorn
Now you can declare final
states and the machine will make sure they have no transitions.
>>> from statemachine import StateMachine, State
>>> class ApprovalMachine(StateMachine):
... """A workflow machine"""
... requested = State("Requested", initial=True)
... accepted = State("Accepted")
... rejected = State("Rejected")
... completed = State("Completed", final=True)
...
... validate = requested.to(accepted, cond="is_ok") | requested.to(rejected)
... release = accepted.to(completed)
... reopen = completed.to(requested)
Traceback (most recent call last):
...
InvalidDefinition: Cannot declare transitions from final state. Invalid state(s): ['completed']
See {ref}final-state
for more details.
- Doctesting all documentation including README (with issues on examples fixed).
- Fix state value misjudged when state value is an "boolean False value" (tks @the5fire)
- Fix returning dict as result of transitions callback.