Skip to content

Commit 7de2ad4

Browse files
committed
fix: Fix sm name from scxml element
1 parent 77362a1 commit 7de2ad4

8 files changed

Lines changed: 20 additions & 38 deletions

File tree

statemachine/engines/async_.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ async def _activate(self, trigger_data: TriggerData, transition: "Transition"):
106106

107107
result += await self.sm._callbacks.async_call(transition.on.key, *args, **kwargs)
108108

109+
assert target # TODO: Temp hack to make mypy happy until we bring SCXML to async
110+
109111
self.sm.current_state = target
110112
event_data.state = target
111113
kwargs["state"] = target

statemachine/engines/base.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ def get_transition_domain(self, transition: Transition) -> "State | None":
195195
and all(state.is_descendant(transition.source) for state in states)
196196
):
197197
return transition.source
198-
elif transition.internal and transition.is_self and transition.target.is_atomic:
198+
elif (
199+
transition.internal
200+
and transition.is_self
201+
and transition.target
202+
and transition.target.is_atomic
203+
):
199204
return transition.source
200205
else:
201206
return self.find_lcca([transition.source] + list(states))
@@ -570,15 +575,18 @@ def add_descendant_states_to_enter(
570575
and info.transition.internal
571576
and (
572577
info.transition.is_self
573-
or info.transition.target.is_descendant(info.transition.source)
578+
or (
579+
info.transition.target
580+
and info.transition.target.is_descendant(info.transition.source)
581+
)
574582
)
575583
):
576584
pass
577585
else:
578586
states_to_enter.add(info)
579587
state = info.target
580588

581-
if state.parallel:
589+
if state and state.parallel:
582590
for child_state in state.states:
583591
if not any(s.target.is_descendant(child_state) for s in states_to_enter):
584592
info_to_add = StateTransition(
@@ -592,7 +600,7 @@ def add_descendant_states_to_enter(
592600
states_for_default_entry,
593601
default_history_content,
594602
)
595-
elif state.is_compound:
603+
elif state and state.is_compound:
596604
states_for_default_entry.add(info)
597605
initial_state = next(s for s in state.states if s.initial)
598606
transition = next(

statemachine/io/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __call__(self, *args, **kwargs) -> Any: ...
1919

2020

2121
class TransitionDict(TypedDict, total=False):
22-
target: str
22+
target: "str | None"
2323
event: "str | None"
2424
internal: bool
2525
initial: bool

statemachine/io/scxml/actions.py

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

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

3232

3333
class ParseTime:

statemachine/io/scxml/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ def parse_scxml(scxml_content: str) -> StateMachineDefinition:
4848
raise ValueError("No scxml element found in document")
4949

5050
initial_state = _parse_initial(scxml.get("initial"))
51+
name = scxml.get("name")
5152

52-
definition = StateMachineDefinition(initial_states=initial_state)
53+
definition = StateMachineDefinition(name=name, initial_states=initial_state)
5354

5455
# Parse datamodel
5556
datamodel = parse_datamodel(scxml)

statemachine/io/scxml/processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def parse_scxml_file(self, path: Path):
3232

3333
def parse_scxml(self, sm_name: str, scxml_content: str):
3434
definition = parse_scxml(scxml_content)
35-
self.process_definition(definition, location=sm_name)
35+
self.process_definition(definition, location=definition.name or sm_name)
3636

3737
def process_definition(self, definition, location: str):
3838
states_dict = self._process_states(definition.states)

statemachine/io/scxml/schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class DataModel:
138138

139139
@dataclass
140140
class StateMachineDefinition:
141+
name: "str | None" = None
141142
states: Dict[str, State] = field(default_factory=dict)
142143
initial_states: Set[str] = field(default_factory=set)
143144
datamodel: "DataModel | None" = None

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

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

0 commit comments

Comments
 (0)