Giter Site home page Giter Site logo

Comments (3)

tomtitherington avatar tomtitherington commented on June 13, 2024

In order to access the state of the machine, you have two options (as per the docs that you linked).

  • inspecting the .state attribute, or
  • calling is_«state name»()

The problem in your case, is that you are trying to access the "state" attribute on the machine instance and not the underlying model instance. i.e. You need to use my_obj.state and not machine.state to get the desired behaviour you are looking for.

from transitions.

aleneum avatar aleneum commented on June 13, 2024

Hello @atk-portcast,

@tomtitherington has already mentioned it. transitions decorates the model passed to a machine with convenience functions such as auto transitions ("to_"), event trigger (e.g. "melt"), state checks ("is_") and so on. With transitions, models are the stateful objects, not machines. However, machines can act as a model which actually is the default case when no model is passed. One machine can manage multiple models, including itself.

from transitions import Machine

class Model:
     pass

# machine acts as a model
machine = Machine(states=["A", "B"], initial="A") 
assert machine.state == "A"
assert machine.is_A()
assert machine.to_B()
assert not machine.is_A()

# model explicitly passed 
model = Model()
machine = Machine(model, states=["A", "B"], initial="A")
# machine.state ! raises Exception
# machine.to_B() ! raises Exception
assert model.state == "A"
assert model.to_B()
machine.add_model(machine, initial="B")  # add machine as a second model
assert model.state == machine.state.  # now machine has been decorated as well

from transitions.

aleneum avatar aleneum commented on June 13, 2024

Closing this since there has been no feedback for over 2 weeks. Feel free to comment if the issue still persists. I will reopen the issue if necessary.

from transitions.

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.