Skip to content

Commit

Permalink
fix: Fix sm name from scxml element
Browse files Browse the repository at this point in the history
  • Loading branch information
fgmacedo committed Dec 22, 2024
1 parent d7cf2ad commit 85626ae
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 38 deletions.
2 changes: 2 additions & 0 deletions statemachine/engines/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ async def _activate(self, trigger_data: TriggerData, transition: "Transition"):

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

assert target # TODO: Temp hack to make mypy happy until we bring SCXML to async

self.sm.current_state = target
event_data.state = target
kwargs["state"] = target
Expand Down
16 changes: 12 additions & 4 deletions statemachine/engines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ def get_transition_domain(self, transition: Transition) -> "State | None":
and all(state.is_descendant(transition.source) for state in states)
):
return transition.source
elif transition.internal and transition.is_self and transition.target.is_atomic:
elif (
transition.internal
and transition.is_self
and transition.target
and transition.target.is_atomic
):
return transition.source
else:
return self.find_lcca([transition.source] + list(states))
Expand Down Expand Up @@ -570,15 +575,18 @@ def add_descendant_states_to_enter(
and info.transition.internal
and (
info.transition.is_self
or info.transition.target.is_descendant(info.transition.source)
or (
info.transition.target
and info.transition.target.is_descendant(info.transition.source)
)
)
):
pass
else:
states_to_enter.add(info)
state = info.target

if state.parallel:
if state and state.parallel:
for child_state in state.states:
if not any(s.target.is_descendant(child_state) for s in states_to_enter):
info_to_add = StateTransition(
Expand All @@ -592,7 +600,7 @@ def add_descendant_states_to_enter(
states_for_default_entry,
default_history_content,
)
elif state.is_compound:
elif state and state.is_compound:
states_for_default_entry.add(info)
initial_state = next(s for s in state.states if s.initial)
transition = next(
Expand Down
2 changes: 1 addition & 1 deletion statemachine/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __call__(self, *args, **kwargs) -> Any: ...


class TransitionDict(TypedDict, total=False):
target: str
target: "str | None"
event: "str | None"
internal: bool
initial: bool
Expand Down
2 changes: 1 addition & 1 deletion statemachine/io/scxml/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .schema import ScriptAction

logger = logging.getLogger(__name__)
protected_attrs = _event_data_kwargs | {"_sessionid", "_ioprocessors"}
protected_attrs = _event_data_kwargs | {"_sessionid", "_ioprocessors", "_name"}


class ParseTime:
Expand Down
3 changes: 2 additions & 1 deletion statemachine/io/scxml/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def parse_scxml(scxml_content: str) -> StateMachineDefinition:
raise ValueError("No scxml element found in document")

Check warning on line 48 in statemachine/io/scxml/parser.py

View check run for this annotation

Codecov / codecov/patch

statemachine/io/scxml/parser.py#L48

Added line #L48 was not covered by tests

initial_state = _parse_initial(scxml.get("initial"))
name = scxml.get("name")

definition = StateMachineDefinition(initial_states=initial_state)
definition = StateMachineDefinition(name=name, initial_states=initial_state)

# Parse datamodel
datamodel = parse_datamodel(scxml)
Expand Down
2 changes: 1 addition & 1 deletion statemachine/io/scxml/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def parse_scxml_file(self, path: Path):

def parse_scxml(self, sm_name: str, scxml_content: str):
definition = parse_scxml(scxml_content)
self.process_definition(definition, location=sm_name)
self.process_definition(definition, location=definition.name or sm_name)

def process_definition(self, definition, location: str):
states_dict = self._process_states(definition.states)
Expand Down
1 change: 1 addition & 0 deletions statemachine/io/scxml/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class DataModel:

@dataclass
class StateMachineDefinition:
name: "str | None" = None
states: Dict[str, State] = field(default_factory=dict)
initial_states: Set[str] = field(default_factory=set)
datamodel: "DataModel | None" = None
30 changes: 0 additions & 30 deletions tests/scxml/w3c/mandatory/test324.fail.md

This file was deleted.

0 comments on commit 85626ae

Please sign in to comment.