Skip to content

Commit a87e670

Browse files
committed
fix: address SonarCloud findings in invoke module
- Prefix unused ctx parameter in StateChartInvoker.run() with underscore - Remove unnecessary async from _spawn_one_async (no await in body) - Add explicit return after swallowing CancelledError with rationale comment - Add comment to empty on_cancel() in test to explain intent
1 parent 3198871 commit a87e670

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

statemachine/invoke.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def __init__(self, child_class: "type[StateChart]"):
179179
self._child_class = child_class
180180
self._child: "StateChart | None" = None
181181

182-
def run(self, ctx: "InvokeContext") -> Any:
182+
def run(self, _ctx: "InvokeContext") -> Any:
183183
self._child = self._child_class()
184184
# The child machine starts automatically in its constructor.
185185
# If it has final states, it will terminate on its own.
@@ -357,7 +357,7 @@ async def spawn_pending_async(self):
357357
)
358358
self._states_to_invoke.clear()
359359

360-
async def _spawn_one_async(self, callback: "CallbackWrapper", **kwargs):
360+
def _spawn_one_async(self, callback: "CallbackWrapper", **kwargs):
361361
state: "State" = kwargs["state"]
362362
ctx = self._make_context(state)
363363
invocation = Invocation(invokeid=ctx.invokeid, state_id=state.id, ctx=ctx)
@@ -394,7 +394,9 @@ async def _run_async_handler(
394394
internal=True,
395395
)
396396
except asyncio.CancelledError:
397-
pass
397+
# Intentionally swallowed: the owning state was exited, so this
398+
# invocation was cancelled — there is nothing to propagate.
399+
return
398400
except Exception as e:
399401
if not ctx.cancelled.is_set():
400402
self.sm.send("error.execution", error=e, internal=True)

tests/test_invoke.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def run(self, ctx: InvokeContext):
111111
return "invoker_result"
112112

113113
def on_cancel(self):
114-
pass
114+
pass # no-op: only verifying the protocol is satisfied
115115

116116
assert isinstance(MyInvoker(), IInvoke)
117117

0 commit comments

Comments
 (0)