Comments (6)
A and B are different checks, but B will be valid only if A is also valid.
This change may necessitate further modifications across a broad range of library uses.
I don't think this will affect any of the examples, or many users of the library who have used the examples as models, but just in case, we can add a warning for both A and B before turning them into hard errors.
Turning either A or B into hard errors is technically a breaking change, but perhaps a minor version bump is enough, since import-time errors should be easily caught by even the simplest test suite.
from python-statemachine.
Hi @twoolie, thank you for bringing this to our attention.
At the moment, this is the expected behavior. As a library, our goal is to accommodate a wide range of use cases. Some state machines, like the "semaphore" example, are designed to run cycles indefinitely and never reach an end state.
However, we are considering your suggestion to implement a check if there's a declared final state, ensuring that all states have a path leading to a final state. This could be a small patch to the library but significant change to users, and may require a major release, as it has the potential to alter the "Public behavior."
What do you think?
We appreciate your input and will give it thorough consideration.
from python-statemachine.
@twoolie I'm more of a fan of approach B since that will also be useful for avoiding human error when creating large state machines. Also, I thought I had this covered on #232 but apparently, I didn't.
What do you think @fgmacedo ?
from python-statemachine.
Hi @fgmacedo
There's two different checks that we could implement that give different guarantees:
A) Check that all non-final states have an outgoing transition. This guarantees that progress is always possible, but allows for infinite looping state machines. (do self-transitions count? i think they should.)
B) If final states exist, check that all non-final states have a path to a final state. This guarantees that the state machine has a path to termination, and the author hasn't forgot a transition that should be there.
I can't find the semaphore example, did you mean traffic light? I don't think that either of these checks would impact that example. For the A check, the traffic light example does have all states with outgoing transitions. The traffic light example has no final states, so we can skip the B check.
As far as altering public behaviour, you could add the check as a warning in the next release, and then change the check to an error in the next (major?) release.
If you're happy with this proposal, I'd be happy to work on the implementation.
from python-statemachine.
I believe that A and B are not mutually exclusive and can both be implemented.
A helps prevent definition errors of dead states, which lead to a stuck SM, by making it necessary to mark a "final" state as final=True
. This change may necessitate further modifications across a broad range of library uses.
B is more likely to be mapped to an error, without necessitating a major version bump.
In my opinion, we should pursue the implementation of both:
- A: Initially, introduce it as a warning for the 2.1.X version, and include a note in the documentation indicating that it will be converted into an exception in the next major release.
- B: Implement as an
InvalidDefinition
. - Enhance the documentation to enumerate all SM validations performed at "import time" and at "instance creation time".
from python-statemachine.
Closed by #410
from python-statemachine.
Related Issues (20)
- Simple question HOT 10
- Generate the code from PlantUML diagrams HOT 2
- Type annotations missing for `initial_state` and `final_states`; leading to linting errors with Pylint/Pyright HOT 3
- Expensive instantiation of StateMachine HOT 3
- AttributeError: object has no attribute 'model' HOT 3
- Enable Multithreading HOT 2
- [Feature request] State machine based workflow for database storage on entity state tracking HOT 1
- Action callback gets called twice when mixing definition methods HOT 1
- Execute a state machine from another state machine HOT 1
- Guards and conditions passed as strings really necessary? HOT 6
- ROS2, state transition not possible HOT 2
- Send a state machine over MQTT / serializing-deserializing a SM HOT 6
- Question: How can I use cond functions to gatekeep, but not fail? HOT 5
- Failed to generate a graphic image HOT 2
- Models instantiated in Djangos setUpTestData seem to skip conditions HOT 5
- @<transition>.cond decorator bug, general question about running code on every transition even if TransitionNotAllowed is raised HOT 3
- Persistence, timeouts, and branching conditionals? HOT 7
- feature request: return to previous state
- sm.current_state.name capitalizes the state name and replaces underscores with spaces HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-statemachine.