Skip to content

Commit 12f5b8f

Browse files
committed
docs(weighted_transitions): add seealso, fix stale refs, inline imports
- Add seealso contextual block for consistency - Remove versionadded 3.0.0 (noise for v3 release) - Remove testsetup block, move imports into first doctest - Remove "Installation" section (was just imports) - Fix stale {ref}`guards` and {ref}`validators-and-guards` → `conditions`
1 parent 9bc4b93 commit 12f5b8f

1 file changed

Lines changed: 13 additions & 26 deletions

File tree

docs/weighted_transitions.md

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,28 @@
22

33
# Weighted transitions
44

5-
```{versionadded} 3.0.0
5+
```{seealso}
6+
See {ref}`conditions` for how the engine selects transitions, and
7+
{ref}`actions` for callbacks that run during transitions.
68
```
79

8-
The `weighted_transitions` utility lets you define **probabilistic transitions** — where
9-
each transition from a state has a relative weight that determines how likely it is to be
10-
selected when the event fires.
10+
The `weighted_transitions` utility lets you define **probabilistic
11+
transitions** — where each transition from a state has a relative weight
12+
that determines how likely it is to be selected when the event fires.
1113

12-
This is a contrib module that works entirely through the existing {ref}`guards` system.
13-
No engine modifications are needed.
14+
This is a contrib module that works entirely through the existing
15+
{ref}`conditions` system. No engine modifications are needed.
1416

15-
## Installation
16-
17-
The module is included in the `python-statemachine` package. Import it from the contrib
18-
namespace:
19-
20-
```python
21-
from statemachine.contrib.weighted import weighted_transitions
22-
23-
# Only needed when passing transition kwargs (cond, on, etc.)
24-
from statemachine.contrib.weighted import to
25-
```
2617

2718
## Basic usage
2819

29-
Pass a **source state** followed by `(target, weight)` tuples. The result is a regular
30-
{ref}`TransitionList` that you assign to a class attribute as an event:
20+
Import `weighted_transitions` and pass a **source state** followed by
21+
`(target, weight)` tuples. The result is a regular {ref}`TransitionList`
22+
that you assign to a class attribute as an event:
3123

32-
```{testsetup}
33-
34-
>>> from statemachine import State, StateChart
24+
```py
3525
>>> from statemachine.contrib.weighted import to, weighted_transitions
3626

37-
```
38-
39-
```py
4027
>>> class GameCharacter(StateChart):
4128
... standing = State(initial=True)
4229
... shift_weight = State()
@@ -243,5 +230,5 @@ Under the hood, `weighted_transitions()`:
243230
5. Only the selected transition's condition returns `True` — the engine picks it.
244231

245232
This means weighted transitions are fully compatible with all engine features:
246-
{ref}`actions`, {ref}`validators-and-guards`, {ref}`listeners`, async engines,
233+
{ref}`actions`, {ref}`conditions`, {ref}`listeners`, async engines,
247234
and {ref}`diagram generation <diagram>`.

0 commit comments

Comments
 (0)