Comments (6)
Hi,
they are created in core.py
in __getattr__
:
def __getattr__(self, name):
if name.startswith('__'):
if name in self.__dict__:
return self.__dict__[name]
else:
raise AttributeError("{} does not exist".format(name))
terms = name.split('_')
if terms[0] in ['before', 'after']:
name = '_'.join(terms[1:])
if name not in self.events:
raise MachineError('Event "%s" is not registered.' % name)
return partial(self.events[name].add_callback, terms[0])
# that's where the magic happens
# on_enter / on_exit queries are concatenated with the current state
# and predefined with partial
elif name.startswith('on_enter') or name.startswith('on_exit'):
state = self.get_state('_'.join(terms[2:]))
return partial(state.add_callback, terms[1])
else:
if name in self.__dict__:
return self.__dict__[name]
else:
raise AttributeError("{} does not exist".format(name))
on_exit_solid
has to be called from the machine, not from the model.
machine.on_exit_solid('say_goodbye')
should work.
from transitions.
Okay,
after some more careful reading what you said and what the documentation states, I guess you are right. Afaik, it does not work the way its stated in the documentation.
from transitions.
Good catch. I'll fix this right now. Thanks @TheMysteriousX!
from transitions.
in core.Machine.add_states
there is a check if an on_enter_State
method exists but it is not created otherwise.
# Add enter/exit callbacks if there are existing bound methods
enter_callback = 'on_enter_' + state_name
if hasattr(self.model, enter_callback) and \
inspect.ismethod(getattr(self.model, enter_callback)):
state.add_callback('enter', enter_callback)
exit_callback = 'on_exit_' + state_name
if hasattr(self.model, exit_callback) and \
inspect.ismethod(getattr(self.model, exit_callback)):
state.add_callback('exit', exit_callback)
from transitions.
I assume we don't want to allow on_enter_* to work on the model itself, right? I mean, we definitely don't want to start patching an arbitrary model class's getattr method. So I'm just going to update the README to be clear about this.
from transitions.
👍 agree
from transitions.
Related Issues (20)
- Mermaid diagrams HOT 4
- maximum recursion depth exceeded while calling a Python object HOT 1
- State transition during on_exception callback causes RecursionError
- "on_exception" is not invoked for "KeyboardInterrupt"
- Explicitly reexport package names
- GraphMachine: set proportional font or allow caller control HOT 3
- AttributeError: 'state' does not exist HOT 3
- prepare func raises Exception altough on_exception is defined
- GraphMachine seems not working for parallel states HOT 1
- 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
- The Event and Machine have cyclic dependency. HOT 3
- Update COPR packages
- get_triggers does not get child states in HierarchicalAsyncMachine HOT 1
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.