Skip to content

Commit 1c1018d

Browse files
committed
fix: Fix parser of sub-final states
1 parent 3e48099 commit 1c1018d

File tree

5 files changed

+40
-73
lines changed

5 files changed

+40
-73
lines changed

docs/releases/3.0.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ but would not match events named `errors.my.custom`, `errorhandler.mistake`, `er
8080

8181
An event designator consisting solely of `*` can be used as a wildcard matching any sequence of tokens, and thus any event.
8282

83+
### Delayed events
84+
85+
Specify an event to run in the near future. The engine will keep track of the execution time
86+
and only process the event when `now > execution_time`.
87+
88+
TODO: Example of delayed events
89+
90+
Also, delayed events can be revoked by it's `send_id`.
91+
8392

8493
## Bugfixes in 3.0.0
8594

statemachine/io/scxml/actions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
from .schema import ScriptAction
2828

2929
logger = logging.getLogger(__name__)
30-
protected_attrs = _event_data_kwargs | {
31-
"_sessionid",
32-
}
30+
protected_attrs = _event_data_kwargs | {"_sessionid", "_ioprocessors"}
3331

3432

3533
class ParseTime:

statemachine/io/scxml/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def parse_state(
142142
child_state = parse_state(child_state_elem, initial_states=initial_states)
143143
child_state.initial = child_state.initial
144144
state.states[child_state.id] = child_state
145+
for child_state_elem in state_elem.findall("final"):
146+
child_state = parse_state(child_state_elem, initial_states=initial_states, is_final=True)
147+
child_state.initial = child_state.initial
148+
state.states[child_state.id] = child_state
145149
for child_state_elem in state_elem.findall("parallel"):
146150
state = parse_state(child_state_elem, initial_states=initial_states, is_parallel=True)
147151
child_state.initial = child_state.initial

tests/scxml/w3c/mandatory/test326.fail.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,38 @@ Final configuration: `['fail']`
88

99
## Logs
1010
```py
11-
DEBUG statemachine.engines.base:base.py:374 States to enter: {S0}
12-
DEBUG statemachine.io.scxml.actions:actions.py:443 Error executing actions
13-
Traceback (most recent call last):
14-
File "/home/macedo/projects/python-statemachine/statemachine/io/scxml/actions.py", line 441, in datamodel
15-
act(machine=machine)
16-
~~~^^^^^^^^^^^^^^^^^
17-
File "/home/macedo/projects/python-statemachine/statemachine/io/scxml/actions.py", line 412, in data_initializer
18-
value = _eval(action.expr, **kwargs)
19-
File "/home/macedo/projects/python-statemachine/statemachine/io/scxml/actions.py", line 125, in _eval
20-
return eval(expr, {}, kwargs)
21-
File "<string>", line 1, in <module>
22-
import sys;exec(eval(sys.stdin.readline()))
23-
^^^^^^^^^^^^^
24-
NameError: name '_ioprocessors' is not defined
11+
DEBUG statemachine.engines.base:base.py:386 States to enter: {S0}
2512
DEBUG statemachine.engines.sync:sync.py:64 Processing loop started: s0
26-
DEBUG statemachine.io.scxml.actions:actions.py:170 Cond Var1 -> None
27-
DEBUG statemachine.io.scxml.actions:actions.py:170 Cond True -> True
28-
DEBUG statemachine.engines.sync:sync.py:89 Eventless/internal queue: {transition from S0 to Fail}
29-
DEBUG statemachine.engines.base:base.py:283 States to exit: {S0}
30-
DEBUG statemachine.engines.base:base.py:374 States to enter: {Fail}
13+
DEBUG statemachine.io.scxml.actions:actions.py:179 Cond Var1 -> <statemachine.io.scxml.processor.IOProcessor object at 0x7f0f23f91190>
14+
DEBUG statemachine.engines.sync:sync.py:89 Eventless/internal queue: {transition from S0 to S1}
15+
DEBUG statemachine.engines.base:base.py:276 States to exit: {S0}
16+
DEBUG statemachine.engines.base:base.py:386 States to enter: {S1}
17+
DEBUG statemachine.io.scxml.actions:actions.py:476 Error executing actions
18+
Traceback (most recent call last):
19+
File "/home/macedo/projects/python-statemachine/statemachine/io/scxml/actions.py", line 472, in __call__
20+
action(*args, **kwargs)
21+
~~~~~~^^^^^^^^^^^^^^^^^
22+
File "/home/macedo/projects/python-statemachine/statemachine/io/scxml/actions.py", line 253, in __call__
23+
raise ValueError(
24+
...<2 lines>...
25+
)
26+
ValueError: <assign> 'location' cannot assign to a protected attribute: _ioprocessors
27+
DEBUG statemachine.engines.sync:sync.py:89 Eventless/internal queue: {transition error.execution from S1 to S2}
28+
DEBUG statemachine.engines.base:base.py:276 States to exit: {S1}
29+
DEBUG statemachine.engines.base:base.py:386 States to enter: {S2}
30+
DEBUG statemachine.io.scxml.actions:actions.py:258 Assign: Var2 = <statemachine.io.scxml.processor.IOProcessor object at 0x7f0f23f915b0>
31+
DEBUG statemachine.io.scxml.actions:actions.py:179 Cond Var1==Var2 -> False
32+
DEBUG statemachine.engines.sync:sync.py:89 Eventless/internal queue: {transition from S2 to Fail}
33+
DEBUG statemachine.engines.base:base.py:276 States to exit: {S2}
34+
DEBUG statemachine.engines.base:base.py:386 States to enter: {Fail}
3135

3236
```
3337

3438
## "On transition" events
3539
```py
36-
DebugEvent(source='s0', event='None', data='{}', target='fail')
40+
DebugEvent(source='s0', event='None', data='{}', target='s1')
41+
DebugEvent(source='s1', event='error.execution', data='{\'event_id\': None, \'error\': ValueError("<assign> \'location\' cannot assign to a protected attribute: _ioprocessors")}', target='s2')
42+
DebugEvent(source='s2', event='None', data='{}', target='fail')
3743
```
3844

3945
## Traceback

tests/scxml/w3c/mandatory/test416.fail.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)