@@ -27,14 +27,15 @@ Transitions now support `cond` and `unless` parameters, to restrict
2727the execution.
2828
2929``` python
30- class ApprovalMachine (StateMachine ):
31- " A workflow machine"
32- requested = State(" Requested" , initial = True )
33- accepted = State(" Accepted" )
34- rejected = State(" Rejected" )
35- completed = State(" Completed" )
30+ class ApprovalMachine (StateMachine ):
31+ " A workflow machine"
32+
33+ requested = State(" Requested" , initial = True )
34+ accepted = State(" Accepted" )
35+ rejected = State(" Rejected" )
36+ completed = State(" Completed" )
3637
37- validate = requested.to(accepted, cond = " is_ok" ) | requested.to(rejected)
38+ validate = requested.to(accepted, cond = " is_ok" ) | requested.to(rejected)
3839```
3940
4041``` {seealso}
@@ -114,9 +115,10 @@ So, the previous code (not valid anymore):
114115``` py
115116class ApprovalMachine (StateMachine ):
116117 " A workflow machine"
117- requested = State(' Requested' , initial = True )
118- accepted = State(' Accepted' )
119- rejected = State(' Rejected' )
118+
119+ requested = State(" Requested" , initial = True )
120+ accepted = State(" Accepted" )
121+ rejected = State(" Rejected" )
120122
121123 validate = requested.to(accepted, rejected)
122124
@@ -133,6 +135,7 @@ Should be rewritten to use {ref}`guards`, like this:
133135``` py
134136class ApprovalMachine (StateMachine ):
135137 " A workflow machine"
138+
136139 requested = State(" Requested" , initial = True )
137140 accepted = State(" Accepted" )
138141 rejected = State(" Rejected" )
@@ -168,14 +171,16 @@ This was the previous behavior, you only got an error when trying to instantiate
168171``` py
169172class CampaignMachine (StateMachine ):
170173 " A workflow machine"
171- draft = State(' Draft' , initial = True )
172- producing = State(' Being produced' )
173- closed = State(' Closed' , initial = True ) # Should raise an Exception when instantiated
174+
175+ draft = State(" Draft" , initial = True )
176+ producing = State(" Being produced" )
177+ closed = State(" Closed" , initial = True ) # Should raise an Exception when instantiated
174178
175179 add_job = draft.to(draft) | producing.to(producing)
176180 produce = draft.to(producing)
177181 deliver = producing.to(closed)
178182
183+
179184with pytest.raises(exceptions.InvalidDefinition):
180185 CampaignMachine()
181186```
@@ -187,6 +192,7 @@ with pytest.raises(exceptions.InvalidDefinition):
187192
188193 class CampaignMachine (StateMachine ):
189194 " A workflow machine"
195+
190196 draft = State(" Draft" , initial = True )
191197 producing = State(" Being produced" )
192198 closed = State(
0 commit comments