Skip to content

Commit 705ecb3

Browse files
committed
fix: Log may contain only the 'label' attr
1 parent deb84b2 commit 705ecb3

4 files changed

Lines changed: 10 additions & 48 deletions

File tree

statemachine/io/scxml/actions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,14 @@ def __init__(self, action: LogAction):
268268
self.action = action
269269

270270
def __call__(self, *args, **kwargs):
271-
value = _eval(self.action.expr, **kwargs)
271+
value = _eval(self.action.expr, **kwargs) if self.action.expr else None
272272

273-
msg = f"{self.action.label}: {value!r}" if self.action.label else f"{value!r}"
273+
if self.action.label and self.action.expr is not None:
274+
msg = f"{self.action.label}: {value!r}"
275+
elif self.action.label:
276+
msg = f"{self.action.label}"
277+
else:
278+
msg = f"{value!r}"
274279
print(msg)
275280

276281

statemachine/io/scxml/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def parse_scxml(scxml_content: str) -> StateMachineDefinition: # noqa: C901
8585

8686
# If the initial states definition does not contain any first level state,
8787
# we find the first level states that are ancestor of the initial states
88-
# and also set them as the initial states.
88+
# and also set them as the initial states
8989
if not set(definition.states.keys()) & definition.initial_states:
9090
not_found = set(definition.initial_states)
9191
for state, parents in visit_states(definition.states.values(), []):
@@ -241,7 +241,7 @@ def parse_assign(element: ET.Element) -> AssignAction:
241241

242242
def parse_log(element: ET.Element) -> LogAction:
243243
label = element.attrib.get("label")
244-
expr = element.attrib["expr"]
244+
expr = element.attrib.get("expr")
245245
return LogAction(label=label, expr=expr)
246246

247247

statemachine/io/scxml/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AssignAction(Action):
3939
@dataclass
4040
class LogAction(Action):
4141
label: "str | None"
42-
expr: str
42+
expr: "str | None"
4343

4444

4545
@dataclass

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

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

0 commit comments

Comments
 (0)