-
Notifications
You must be signed in to change notification settings - Fork 561
Description
Hi, At this point in the game I'm assuming that there is an undocumented step that I'm not doing
that makes the example work.
Maybe a function named "change_shape" ?
If so, then what does change_shape() look like?
This is the section titled: "Reflexive transitions from multiple states"
The tutorial states (pun intended):
A reflexive trigger (trigger that has the same state as source and destination) can easily be added specifying = as destination. This is handy if the same reflexive trigger should be added to multiple states. For example:
machine.add_transition('touch', ['liquid', 'gas', 'plasma'], '=', after='change_shape')
This will add reflexive transitions for all three states with touch() as trigger and with change_shape executed after each trigger.
My code to demonstrate:
class Matter(object):
pass
lump = Matter()
from transitions import Machine
machine = Machine(model=lump, states=['solid', 'liquid', 'gas', 'plasma'], initial='solid')
lump.state
states=['solid', 'liquid', 'gas', 'plasma']
transitions = [
{ 'trigger': 'melt', 'source': 'solid', 'dest': 'liquid' },
{ 'trigger': 'evaporate', 'source': 'liquid', 'dest': 'gas' },
{ 'trigger': 'sublimate', 'source': 'solid', 'dest': 'gas' },
{ 'trigger': 'ionize', 'source': 'gas', 'dest': 'plasma' }
]
machine = Machine(lump, states=states, transitions=transitions, initial='liquid')
lump.state
-> 'liquid'
machine.add_transition('touch', ['liquid', 'gas', 'plasma'], '=', after='change_shape')
lump.touch()
->
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 1210, in resolve_callable
func = getattr(event_data.model, func)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Matter' object has no attribute 'change_shape'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 1217, in resolve_callable
module_name, func_name = func.rsplit('.', 1)
^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 406, in trigger
return self.machine._process(func)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 1240, in _process
return trigger()
^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 420, in _trigger
self._process(event_data)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 443, in _process
if trans.execute(event_data):
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 280, in execute
event_data.machine.callbacks(itertools.chain(self.after, event_data.machine.after_state_change), event_data)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 1175, in callbacks
self.callback(func, event_data)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 1192, in callback
func = self.resolve_callable(func, event_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/transitions/core.py", line 1223, in resolve_callable
raise AttributeError("Callable with name '%s' could neither be retrieved from the passed "
AttributeError: Callable with name 'change_shape' could neither be retrieved from the passed model nor imported from a module.