Skip to content

Commit e8c1feb

Browse files
authored
feat: allow_event_without_transition (#364)
1 parent de5d085 commit e8c1feb

22 files changed

Lines changed: 247 additions & 79 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ There's a lot more to cover, please take a look at our docs:
298298
https://python-statemachine.readthedocs.io.
299299

300300

301-
## Contributing
301+
## Contributing to the project
302302

303303
* <a class="github-button" href="https://github.com/fgmacedo/python-statemachine" data-icon="octicon-star" aria-label="Star fgmacedo/python-statemachine on GitHub">Star this project</a>
304304
* <a class="github-button" href="https://github.com/fgmacedo/python-statemachine/issues" data-icon="octicon-issue-opened" aria-label="Issue fgmacedo/python-statemachine on GitHub">Open an Issue</a>

docs/actions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Actions
22

3-
Action is the way a StateMachine can cause things to happen in the
3+
Action is the way a {ref}`StateMachine` can cause things to happen in the
44
outside world, and indeed they are the main reason why they exist at all.
55

66
The main point of introducing a state machine is for the
@@ -26,7 +26,7 @@ when something changes and are not bounded to a specific state or event:
2626

2727
- `after_transition()`
2828

29-
The follow example can get you an overview of the "generic" callbacks available:
29+
The following example can get you an overview of the "generic" callbacks available:
3030

3131
```py
3232
>>> from statemachine import StateMachine, State
@@ -162,14 +162,14 @@ It's also possible to use an event name as action.
162162

163163
## Transition actions
164164

165-
For each {ref}`event`, you can register `before`, `on` and `after` callbacks.
165+
For each {ref}`event`, you can register `before`, `on`, and `after` callbacks.
166166

167167
### Declare transition actions by naming convention
168168

169169
The action will be registered for every {ref}`transition` associated with the event.
170170

171-
Callbacks by naming convention will be searched on the StateMachine and on the
172-
model, using the patterns:
171+
Callbacks by naming convention will be searched on the StateMachine and the model,
172+
using the patterns:
173173

174174
- `before_<event>()`
175175

@@ -337,7 +337,7 @@ Actions and Guards will be executed in the following order:
337337
(dynamic-dispatch)=
338338
## Dynamic dispatch
339339

340-
`python-statemachine` implements a custom dispatch mechanism on all those available Actions and
340+
{ref}`statemachine` implements a custom dispatch mechanism on all those available Actions and
341341
Guards. This means that you can declare an arbitrary number of `*args` and `**kwargs`, and the
342342
library will match your method signature of what's expected to receive with the provided arguments.
343343

@@ -359,7 +359,7 @@ For your convenience, all these parameters are available for you on any Action o
359359
: All keyword arguments provided on the {ref}`Event`.
360360

361361
`event_data`
362-
: A reference to `EventData` instance.
362+
: A reference to {ref}`EventData` instance.
363363

364364
`event`
365365
: The {ref}`Event` that was triggered.

docs/api.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# API
2+
3+
## StateMachine
4+
5+
```{eval-rst}
6+
.. autoclass:: statemachine.statemachine.StateMachine
7+
:members:
8+
:undoc-members:
9+
```
10+
11+
## State
12+
13+
```{seealso}
14+
{ref}`States` reference.
15+
```
16+
17+
18+
```{eval-rst}
19+
.. autoclass:: statemachine.state.State
20+
:members:
21+
```
22+
23+
## Transition
24+
25+
```{seealso}
26+
{ref}`Transitions` reference.
27+
```
28+
29+
```{eval-rst}
30+
.. autoclass:: statemachine.transition.Transition
31+
:members:
32+
```
33+
34+
## TransitionList
35+
36+
```{eval-rst}
37+
.. autoclass:: statemachine.transition_list.TransitionList
38+
:members:
39+
```
40+
41+
## Model
42+
43+
```{seealso}
44+
{ref}`Domain models` reference.
45+
```
46+
47+
48+
```{eval-rst}
49+
.. autoclass:: statemachine.model.Model
50+
:members:
51+
```
52+
53+
## TriggerData
54+
55+
56+
```{eval-rst}
57+
.. autoclass:: statemachine.event_data.TriggerData
58+
:members:
59+
```
60+
61+
## EventData
62+
63+
```{eval-rst}
64+
.. autoclass:: statemachine.event_data.EventData
65+
:members:
66+
```

docs/diagram.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Diagrams
22

3-
You can generate diagrams from your state machine.
3+
You can generate diagrams from your {ref}`StateMachine`.
44

55
```{note}
66
This functionality depends on [pydot](https://github.com/pydot/pydot), it means that you need to
7-
have pydot installed on your system. pydot is a Python library that allows you to create and
7+
have `pydot` installed on your system. pydot is a Python library that allows you to create and
88
manipulate graphs in [Graphviz](https://graphviz.org/)'s
99
[dot language](https://graphviz.org/doc/info/lang.html).
1010
@@ -59,7 +59,7 @@ As this one:
5959
![OrderControl](images/order_control_machine_initial.png)
6060

6161

62-
The current state is also highlighted:
62+
The current {ref}`state` is also highlighted:
6363

6464
``` py
6565

docs/guards.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(validators-and-guards)=
22
# Validators and guards
33

4-
Validations and Guards are checked before an transition is started. They are meant to stop a
4+
Validations and Guards are checked before a transition is started. They are meant to stop a
55
transition to occur.
66

7-
The main difference, is that {ref}`validators` raise exceptions to stop the flow, and {ref}`guards`
7+
The main difference is that {ref}`validators` raise exceptions to stop the flow, and {ref}`guards`
88
act like predicates that shall resolve to a ``boolean`` value.
99

1010
```{seealso}
@@ -16,16 +16,16 @@ for all the available callbacks, being validators and guards or {ref}`actions`.
1616

1717
Also known as **Conditional transition**.
1818

19-
A guard is a condition that may be checked when a statemachine wants to handle
20-
an {ref}`event`. A guard is declared on the {ref}`transition`, and when that transition
19+
A guard is a condition that may be checked when a {ref}`statemachine` wants to handle
20+
an {ref}`event`. A guard is declared on the {ref}`transition`, and when that {ref}`transition`
2121
would trigger, then the guard (if any) is checked. If the guard is `True`
2222
then the transition does happen. If the guard is `False`, the transition
2323
is ignored.
2424

25-
When transitions have guards, then it's possible to define two or more
26-
transitions for the same event from the same {ref}`state`. When the event happens, then
25+
When {ref}`transitions` have guards, then it's possible to define two or more
26+
transitions for the same {ref}`event` from the same {ref}`state`. When the {ref}`event` happens, then
2727
the guarded transitions are checked, one by one, and the first transition
28-
whose guard is true will be used, the others will be ignored.
28+
whose guard is true will be used, and the others will be ignored.
2929

3030
A guard is generally a boolean function or boolean variable and must not have any side effects.
3131
Side effects are reserved for {ref}`actions`.
@@ -66,7 +66,7 @@ So, a condition `s1.to(s2, cond=lambda: [])` will evaluate as `False`, as an emp
6666

6767

6868
Are like {ref}`guards`, but instead of evaluating to boolean, they are expected to raise an
69-
exception to stop the flow. It may be useful for imperative style programming when you don't
69+
exception to stop the flow. It may be useful for imperative-style programming when you don't
7070
want to continue evaluating other possible transitions and exit immediately.
7171

7272
* Single validator: `validators="validator"`

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mixins
1717
integrations
1818
diagram
1919
processing_model
20+
api
2021
auto_examples/index
2122
contributing
2223
authors

docs/integrations.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33

44
## Django integration
55

6-
When used in a Django App, this library implements an auto-discovery hook similar to how Django's built-in **admin** [autodiscover](https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.autodiscover).
6+
When used in a Django App, this library implements an auto-discovery hook similar to how Django's
7+
built-in **admin** [autodiscover](https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.autodiscover).
78

89
> This library attempts to import an **statemachine** or **statemachines** module in each installed
910
> application. Such modules are expected to register `StateMachine` classes to be used with
1011
> the {ref}`MachineMixin`.
1112
1213

1314
```{hint}
14-
When using `python-statemachine` to control the state of a Django model, we advise keeping the ``StateMachine`` definitions on their modules.
15+
When using `python-statemachine` to control the state of a Django model, we advise keeping the
16+
{ref}`StateMachine` definitions on their own modules.
1517
1618
So as circular references may occur, and as a way to help you organize your
1719
code, if you put state machines on modules named as mentioned above inside installed
18-
Django Apps, these `StateMachine` classes will be automatically
20+
Django Apps, these {ref}`StateMachine` classes will be automatically
1921
imported and registered.
2022
2123
This is only an advice, nothing stops you do declare your state machine alongside your models.

docs/mixins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Mixins
33

4-
Your model can be inherited from a custom mixin to auto-instantiate a state machine.
4+
Your {ref}`domain models` can be inherited from a custom mixin to auto-instantiate a {ref}`statemachine`.
55

66
## MachineMixin
77

docs/models.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ If you don't pass an explicit model instance, this simple `Model` will be used:
1313
:linenos:
1414
```
1515

16-
```{eval-rst}
17-
.. autoclass:: statemachine.model.Model
18-
:members:
19-
```
2016

2117
```{seealso}
22-
See the {ref}`sphx_glr_auto_examples_order_control_rich_model_machine.py` as example of using a domain object to hold attributes and methods to be used on the `StateMachine` definition.
18+
See the {ref}`sphx_glr_auto_examples_order_control_rich_model_machine.py` as example of using a
19+
domain object to hold attributes and methods to be used on the `StateMachine` definition.
2320
```
2421

2522
```{hint}
26-
Domain models are registered as {ref}`observers`, so you can have the same level of functionalities provided to the built-in `StateMachine`, such as implementing all callbacks and guards on your domain model and keeping only the definition of states and transitions on
27-
the `StateMachine`.
23+
Domain models are registered as {ref}`observers`, so you can have the same level of functionalities
24+
provided to the built-in {ref}`StateMachine`, such as implementing all {ref}`actions` and
25+
{ref}`guards` on your domain model and keeping only the definition of {ref}`states` and
26+
{ref}`transitions` on the {ref}`StateMachine`.
2827
```

docs/releases/1.0.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This is the last release to support Python 2.7, 3.5, and 3.6.
2121
## What's new in 1.0
2222

2323

24-
### Validators and Guards
24+
### Added validators and Guards
2525

2626
Transitions now support `cond` and `unless` parameters, to restrict
2727
the execution.

0 commit comments

Comments
 (0)