Repository navigation
v1.0.1
#315
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
StateMachine 1.0.1
January 11, 2023
Welcome to StateMachine 1.0!
This version is a huge refactoring adding a lot of new and exiting features. We hope that
you enjoy.
These release notes cover the , as well as
some backwards incompatible changes you'll
want to be aware of when upgrading from StateMachine 0.9.0 or earlier. We've
begun the deprecation process for some features.
Python compatibility in 1.0
StateMachine 1.0 supports Python 2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, and 3.11.
This is the last release to support Python 2.7, 3.5 and 3.6.
What's new in 1.0
Validators and Guards
Transitions now support
condandunlessparameters, to restrictthe execution.
Support for diagrams
You can generate diagrams from your statemachine.
Example:
Unified dispatch mecanism for callbacks (actions and guards)
Every single callback, being
actionsorguards, is now handled equally by the library.Also, we've improved the internals in a way that you can implement your callbacks with any
number of arbritrary positional or keyword arguments (
*args, **kwargs), and the dispatch willmatch the available arguments with your method signature.
This means that if on your
on_enter_<state>()oron_execute_<event>()method, you alsoneed to know the
source(state), or theevent(event), or access a keywordargument passed with the trigger, you're covered. Just add this parameter to the method and It
will be passed by the dispatch mechanics.
Example of what's available:
Add observers to a running StateMachine
Observers are a way do generically add behaviour to a StateMachine without
changing it's internal implementation.
The
StateMachineitself is registered as an observer, so by usingStateMachine.add_observer()an external object can have the same level of functionalities provided to the built-in class.
Minor features in 1.0
StateMachineclass.stateis now entered when the machine starts. Theactions, if defined,on_enter_stateandon_enter_<state>are now called.Backwards incompatible changes in 1.0
Multiple targets from the same origin state
Prior to this release, as we didn't have
validators-and-guards, there wasn't an elegant wayto declare multiples target states starting from the same pair (event, state). But the library
allowed a near-hackish way, by declaring a target state as the result of the
on_<event>callback.So, the previous code (not valid anymore):
Should be rewriten to use
guards, like this:StateMachine now enters the initial state
This issue was reported at #265.
Now StateMachine will execute the actions associated with the
on_enter_stateandon_enter_<state>when initialized, if they exists.Integrity is checked at class definition
Statemachine integrity checks are now performed at class declaration (import time) instead of on
instance creation. This allows early feedback of invalid definitions.
This was the previous behaviour, you only got an error when trying to instantiate a StateMachine:
Not this is performed as the class definition is performed:
Other backwards incompatible changes in 1.0
to perform monkey-patching to add callbacks at runtime (not a bad thing after all).
TransitionNotAllowedchanged internal attr fromtransitiontoevent.CombinedTransitiondoes not exist anymore.Statenow holds a flatTransitionlistcalled
TransitionListthat implements deORoperator. This turns a valid StateMachinetraversal much easier:
[transition for state in machine.states for transition in state.transitions].StateMachine.get_transitionis removed. Seeevent.MultipleStatesFoundandMultipleTransitionCallbacksFoundare removed.Since now you can have more than one callback defined to the same transition.
on_enter_stateandon_exit_statenow accepts any combination of parameters following thedynamic-dispatchrules. Previously it only accepted thestateparam.Transition.__init__paramon_executerenamed to simplyon, and now follows thedynamic-dispatch.Transition.destinationsremoved in favor ofTransition.target(following SCXML convention).Now each transition only points to a unique target. Each
source->targetpair is holded by asingle
Transition.Deprecated features in 1.0
Statemachine class
StateMachine.runis deprecated in favor ofStateMachine.send.StateMachine.allowed_transitionsis deprecated in favor ofStateMachine.allowed_events.Statemachine.is_<state>is deprecated in favor ofStateMachine.<state>.is_active.State class
State.identificationis deprecated in favor ofState.id.This discussion was created from the release v1.0.1.
All reactions