Skip to content

Commit fbc26c1

Browse files
committed
chore: Declaring new base StateChart with new defaults and keeping StateMachine for backwards compatibility
1 parent eec118a commit fbc26c1

24 files changed

Lines changed: 110 additions & 83 deletions

conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
@pytest.fixture(autouse=True, scope="session")
88
def add_doctest_context(doctest_namespace): # noqa: PT004
9-
from statemachine import State, StateMachine
9+
from statemachine import State
10+
from statemachine import StateMachine
1011
from statemachine.utils import run_async_from_sync
1112

1213
class ContribAsyncio:

docs/guards.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A conditional transition occurs only if specific conditions or criteria are met.
2222

2323
When a transition is conditional, it includes a condition (also known as a _guard_) that must be satisfied for the transition to take place. If the condition is not met, the transition does not occur, and the state machine remains in its current state or follows an alternative path.
2424

25-
This feature allows for multiple transitions on the same {ref}`event`, with each {ref}`transition` checked in the order they are declared. A condition acts like a predicate (a function that evaluates to true/false) and is checked when a {ref}`statemachine` handles an {ref}`event` with a transition from the current state bound to this event. The first transition that meets the conditions (if any) is executed. If none of the transitions meet the conditions, the state machine either raises an exception or does nothing (see the `allow_event_without_transition` parameter of {ref}`StateMachine`).
25+
This feature allows for multiple transitions on the same {ref}`event`, with each {ref}`transition` checked in the order they are declared. A condition acts like a predicate (a function that evaluates to true/false) and is checked when a {ref}`statemachine` handles an {ref}`event` with a transition from the current state bound to this event. The first transition that meets the conditions (if any) is executed. If none of the transitions meet the conditions, the state machine either raises an exception or does nothing (see the `allow_event_without_transition` class attribute of {ref}`StateMachine`).
2626

2727
When {ref}`transitions` have guards, it is possible to define two or more transitions for the same {ref}`event` from the same {ref}`state`. When the {ref}`event` occurs, the guarded transitions are checked one by one, and the first transition whose guard is true will be executed, while the others will be ignored.
2828

2.25 KB
Loading
-4.69 KB
Loading
1.51 KB
Loading
959 Bytes
Loading
329 Bytes
Loading

docs/releases/2.0.0.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ including tolerance to unknown {ref}`event` triggers.
8989
The default value is ``False``, that keeps the backward compatible behavior of when an
9090
event does not result in a {ref}`transition`, an exception ``TransitionNotAllowed`` will be raised.
9191

92-
```py
92+
```
93+
>>> import pytest
94+
>>> pytest.skip("Since 3.0.0 `allow_event_without_transition` is now a class attribute.")
95+
9396
>>> sm = ApprovalMachine(allow_event_without_transition=True)
9497
9598
>>> sm.send("unknow_event_name")

docs/releases/3.0.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,12 @@ def on_validate(self, previous_configuration):
217217
return "congrats!"
218218

219219
```
220+
221+
222+
### Configuring the event without transition behaviour
223+
224+
The `allow_event_without_transition` was previously configured as an init parameter, now it's a class-level
225+
attribute.
226+
227+
Defaults to `False` in `StateMachine` class to preserve maximum backwards compatibility.
228+

statemachine/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from .event import Event
22
from .state import State
3+
from .statemachine import StateChart
34
from .statemachine import StateMachine
45

56
__author__ = """Fernando Macedo"""
67
__email__ = "fgmacedo@gmail.com"
78
__version__ = "2.5.0"
89

9-
__all__ = ["StateMachine", "State", "Event"]
10+
__all__ = ["StateChart", "StateMachine", "State", "Event"]

0 commit comments

Comments
 (0)