Skip to content

Commit 3e48099

Browse files
committed
docs: Release example of create_machine_class_from_definition
1 parent 8210da3 commit 3e48099

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

docs/releases/3.0.0.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ Statecharts are there! Now the library has support for Compound and Parallel sta
1010

1111
StateMachine 3.0.0 supports Python 3.9, 3.10, 3.11, 3.12, and 3.13.
1212

13+
14+
### Create state machine class from a dict definition
15+
16+
Dinamically create state machine classes by using `create_machine_class_from_definition`.
17+
18+
19+
``` py
20+
>>> from statemachine.io import create_machine_class_from_definition
21+
22+
>>> machine = create_machine_class_from_definition(
23+
... "TrafficLightMachine",
24+
... **{
25+
... "states": {
26+
... "green": {"initial": True, "on": {"change": [{"target": "yellow"}]}},
27+
... "yellow": {"on": {"change": [{"target": "red"}]}},
28+
... "red": {"on": {"change": [{"target": "green"}]}},
29+
... },
30+
... }
31+
... )
32+
33+
>>> sm = machine()
34+
>>> sm.green.is_active
35+
True
36+
>>> sm.send("change")
37+
>>> sm.yellow.is_active
38+
True
39+
40+
```
41+
42+
1343
### In(state) checks in condition expressions
1444

1545
Now a condition can check if the state machine current set of active states (a.k.a `configuration`) contains a state using the syntax `cond="In('<state-id>')"`.

statemachine/event_data.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class TriggerData:
2525
Allow revoking a delayed :ref:`TriggerData` instance.
2626
"""
2727

28-
_target: "str | None" = field(init=False, compare=False, default=None)
29-
3028
execution_time: float = field(default=0.0)
3129
"""The time at which the :ref:`Event` should run."""
3230

0 commit comments

Comments
 (0)