You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guards.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,9 +65,20 @@ The mini-language is based on Python's built-in language and the [`ast`](https:/
65
65
1.`not` / `!` — Logical negation
66
66
2.`and` / `^` — Logical conjunction
67
67
3.`or` / `v` — Logical disjunction
68
+
4.`or` / `v` — Logical disjunction
68
69
- These operators are case-sensitive (e.g., `NOT` and `Not` are not equivalent to `not` and will raise syntax errors).
69
70
- Both formats can be used interchangeably, so `!sauron_alive` and `not sauron_alive` are equivalent.
70
71
72
+
2.**Comparisson operators**:
73
+
- The following comparison operators are supported:
74
+
1.`>` — Greather than.
75
+
2.`>=` — Greather than or equal.
76
+
3.`==` — Equal.
77
+
4.`!=` — Not equal.
78
+
5.`<` — Lower than.
79
+
6.`<=` — Lower than or equal.
80
+
- See the [comparisons](https://docs.python.org/3/reference/expressions.html#comparisons) from Python's.
81
+
71
82
3.**Parentheses for precedence**:
72
83
- When operators with the same precedence appear in the expression, evaluation proceeds from left to right, unless parentheses specify a different order.
73
84
- Parentheses `(` and `)` are supported to control the order of evaluation in expressions.
You can now declare that a state is accessible from any other state with a simple constructor. Using `State.from_.any()`, the state machine meta class automatically creates transitions from all non-final states to the target state.
16
+
17
+
Furthermore, both `State.from_.itself()` and `State.to.itself()` have been refactored to support type hints and are now fully visible for code completion in your preferred editor.
### Allowed events are now bounded to the state machine instance
50
+
51
+
Since 2.0, the state machine can return a list of allowed events given the current state:
52
+
53
+
```
54
+
>>> sm = AccountStateMachine()
55
+
>>> [str(e) for e in sm.allowed_events]
56
+
['suspend', 'overdraft', 'close_account']
57
+
58
+
```
59
+
60
+
`Event` instances are now bound to the state machine instance, allowing you to pass the event by reference and call it like a method, which triggers the event in the state machine.
61
+
62
+
You can think of the event as an implementation of the **command** design pattern.
63
+
64
+
On this example, we iterate until the state machine reaches a final state,
65
+
listing the current state allowed events and executing the simulated user choice:
... start = Event(created.to(started), name="Launch the machine")
165
+
...
166
+
...@start.on
167
+
...defcall_service(self):
168
+
...return"calling..."
169
+
...
170
+
171
+
>>> sm = StartMachine()
172
+
>>> sm.start()
173
+
'calling...'
174
+
175
+
176
+
```
177
+
178
+
179
+
## Bugfixes in 2.5.0
180
+
181
+
- Fixes [#500](https://github.com/fgmacedo/python-statemachine/issues/500) issue adding support for Pickle.
182
+
183
+
184
+
## Misc in 2.5.0
185
+
186
+
- We're now using `uv`[#491](https://github.com/fgmacedo/python-statemachine/issues/491).
187
+
- Simplification of the engines code [#498](https://github.com/fgmacedo/python-statemachine/pull/498).
188
+
- The dispatcher and callback modules where refactored with improved separation of concerns [#490](https://github.com/fgmacedo/python-statemachine/pull/490).
0 commit comments