|
| 1 | +# StateMachine 2.6.0 |
| 2 | + |
| 3 | +*February 2026* |
| 4 | + |
| 5 | +## What's new in 2.6.0 |
| 6 | + |
| 7 | +This release adds the {ref}`StateMachine.enabled_events` method, Python 3.14 support, |
| 8 | +a significant performance improvement for callback dispatch, and several bugfixes |
| 9 | +for async condition expressions, type checker compatibility, and Django integration. |
| 10 | + |
| 11 | +### Python compatibility in 2.6.0 |
| 12 | + |
| 13 | +StateMachine 2.6.0 supports Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, and 3.14. |
| 14 | + |
| 15 | +### Checking enabled events |
| 16 | + |
| 17 | +A new {ref}`StateMachine.enabled_events` method lets you query which events have their |
| 18 | +`cond`/`unless` guards currently satisfied, going beyond {ref}`StateMachine.allowed_events` |
| 19 | +which only checks reachability from the current state. |
| 20 | + |
| 21 | +This is particularly useful for **UI scenarios** where you want to enable or disable buttons |
| 22 | +based on whether an event's conditions are met at runtime. |
| 23 | + |
| 24 | +```{testsetup} |
| 25 | +
|
| 26 | +>>> from statemachine import StateMachine, State |
| 27 | +
|
| 28 | +``` |
| 29 | + |
| 30 | +```py |
| 31 | +>>> class ApprovalMachine(StateMachine): |
| 32 | +... pending = State(initial=True) |
| 33 | +... approved = State(final=True) |
| 34 | +... rejected = State(final=True) |
| 35 | +... |
| 36 | +... approve = pending.to(approved, cond="is_manager") |
| 37 | +... reject = pending.to(rejected) |
| 38 | +... |
| 39 | +... is_manager = False |
| 40 | + |
| 41 | +>>> sm = ApprovalMachine() |
| 42 | + |
| 43 | +>>> [e.id for e in sm.allowed_events] |
| 44 | +['approve', 'reject'] |
| 45 | + |
| 46 | +>>> [e.id for e in sm.enabled_events()] |
| 47 | +['reject'] |
| 48 | + |
| 49 | +>>> sm.is_manager = True |
| 50 | + |
| 51 | +>>> [e.id for e in sm.enabled_events()] |
| 52 | +['approve', 'reject'] |
| 53 | + |
| 54 | +``` |
| 55 | + |
| 56 | +Since conditions may depend on runtime arguments, any `*args`/`**kwargs` passed to |
| 57 | +`enabled_events()` are forwarded to the condition callbacks: |
| 58 | + |
| 59 | +```py |
| 60 | +>>> class TaskMachine(StateMachine): |
| 61 | +... idle = State(initial=True) |
| 62 | +... running = State(final=True) |
| 63 | +... |
| 64 | +... start = idle.to(running, cond="has_enough_resources") |
| 65 | +... |
| 66 | +... def has_enough_resources(self, cpu=0): |
| 67 | +... return cpu >= 4 |
| 68 | + |
| 69 | +>>> sm = TaskMachine() |
| 70 | + |
| 71 | +>>> sm.enabled_events() |
| 72 | +[] |
| 73 | + |
| 74 | +>>> [e.id for e in sm.enabled_events(cpu=8)] |
| 75 | +['start'] |
| 76 | + |
| 77 | +``` |
| 78 | + |
| 79 | +```{seealso} |
| 80 | +See {ref}`Checking enabled events` in the Guards documentation for more details. |
| 81 | +``` |
| 82 | + |
| 83 | +### Performance: cached signature binding |
| 84 | + |
| 85 | +Callback dispatch is now significantly faster thanks to cached signature binding in |
| 86 | +`SignatureAdapter`. The first call to a callback computes the argument binding and |
| 87 | +caches a fast-path template; subsequent calls with the same argument shape skip the |
| 88 | +full binding logic. |
| 89 | + |
| 90 | +This results in approximately **60% faster** `bind_expected()` calls and |
| 91 | +around **30% end-to-end improvement** on hot transition paths. |
| 92 | + |
| 93 | +See [#548](https://github.com/fgmacedo/python-statemachine/issues/548) for benchmarks. |
| 94 | + |
| 95 | + |
| 96 | +## Bugfixes in 2.6.0 |
| 97 | + |
| 98 | +- Fixes [#531](https://github.com/fgmacedo/python-statemachine/issues/531) domain model |
| 99 | + with falsy `__bool__` was being replaced by the default `Model()`. |
| 100 | +- Fixes [#535](https://github.com/fgmacedo/python-statemachine/issues/535) async predicates |
| 101 | + in condition expressions (`not`, `and`, `or`) were not being awaited, causing guards to |
| 102 | + silently return incorrect results. |
| 103 | +- Fixes [#548](https://github.com/fgmacedo/python-statemachine/issues/548) |
| 104 | + `VAR_POSITIONAL` and kwargs precedence bugs in the signature binding cache introduced |
| 105 | + by the performance optimization. |
| 106 | +- Fixes [#511](https://github.com/fgmacedo/python-statemachine/issues/511) Pyright/Pylance |
| 107 | + false positive "Argument missing for parameter f" when calling events. Static analyzers |
| 108 | + could not follow the metaclass transformation from `TransitionList` to `Event`. |
| 109 | +- Fixes [#551](https://github.com/fgmacedo/python-statemachine/issues/551) `MachineMixin` |
| 110 | + now gracefully skips state machine initialization for Django historical models in data |
| 111 | + migrations, instead of raising `ValueError`. |
| 112 | +- Fixes [#526](https://github.com/fgmacedo/python-statemachine/issues/526) sanitize project |
| 113 | + path on Windows for documentation builds. |
| 114 | + |
| 115 | + |
| 116 | +## Misc in 2.6.0 |
| 117 | + |
| 118 | +- Added Python 3.14 support [#552](https://github.com/fgmacedo/python-statemachine/pull/552). |
| 119 | +- Upgraded dev dependencies: ruff to 0.15.0, mypy to 1.14.1 |
| 120 | + [#552](https://github.com/fgmacedo/python-statemachine/pull/552). |
| 121 | +- Clarified conditional transition evaluation order in documentation |
| 122 | + [#546](https://github.com/fgmacedo/python-statemachine/pull/546). |
| 123 | +- Added pydot DPI resolution settings to diagram documentation |
| 124 | + [#514](https://github.com/fgmacedo/python-statemachine/pull/514). |
| 125 | +- Fixed miscellaneous typos in documentation |
| 126 | + [#522](https://github.com/fgmacedo/python-statemachine/pull/522). |
| 127 | +- Removed Python 3.7 from CI build matrix |
| 128 | + [ef351d5](https://github.com/fgmacedo/python-statemachine/commit/ef351d5). |
0 commit comments