Giter Site home page Giter Site logo

Comments (6)

twoolie avatar twoolie commented on June 5, 2024 2

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.

fgmacedo avatar fgmacedo commented on June 5, 2024 1

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.

rafaelrds avatar rafaelrds commented on June 5, 2024 1

@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.

twoolie avatar twoolie commented on June 5, 2024

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.

fgmacedo avatar fgmacedo commented on June 5, 2024

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:

  1. 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.
  2. B: Implement as an InvalidDefinition.
  3. Enhance the documentation to enumerate all SM validations performed at "import time" and at "instance creation time".

from python-statemachine.

fgmacedo avatar fgmacedo commented on June 5, 2024

Closed by #410

from python-statemachine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.