Comments (3)
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.
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.
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)
- AsyncMachine transitions fail when a list of `State` objects are passed in to the FSM. HOT 2
- get_triggers does not work HOT 3
- Cannot use Pydantic `BaseModel` class for models HOT 2
- All possible transitions are initialized, instead of those provided as an argument. HOT 2
- Machine get into wrong state. HOT 1
- after_state_change not triggered by set_state HOT 2
- AsyncMachine with queued transitions breaks when transition is cancelled
- AsyncMachine transitions aren't atomic HOT 4
- The Event and Machine have cyclic dependency. HOT 3
- Update COPR packages
- get_triggers does not get child states in HierarchicalAsyncMachine HOT 3
- may_ function in parallel state does not report correct value HOT 1
- 3.12 Performance HOT 10
- Call triggers by name HOT 2
- New version release HOT 5
- Very confusing in inherited HierarchicalMachine. HOT 2
- Pylance attributeerror on generated members HOT 6
- 😭 How do you specify final state? The front page docs do not say HOT 1
- Is it normal to have a bunch of warnings of "event doesn't exist" for parallel machines (with disjoint event sets)? HOT 2
- Provide features to ease static type checking HOT 6
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 transitions.