Skip to content

feat: add enabled_events() method (#520)#559

Merged
fgmacedo merged 5 commits intodevelopfrom
feat/enabled-events-520
Feb 13, 2026
Merged

feat: add enabled_events() method (#520)#559
fgmacedo merged 5 commits intodevelopfrom
feat/enabled-events-520

Conversation

@fgmacedo
Copy link
Owner

@fgmacedo fgmacedo commented Feb 13, 2026

Summary

  • Add enabled_events(*args, **kwargs) method that evaluates cond/unless guards and returns only events whose conditions are satisfied
  • Works with both sync and async engines, forwarding *args/**kwargs to condition callbacks
  • Treats condition exceptions as enabled (permissive — only excludes events we're certain are disabled)
  • Add documentation with doctested examples to docs/guards.md

Closes #520

…544)

When an async SM is pickled/deepcopied (e.g. via multiprocessing), the
engine queue is not preserved. __setstate__ recreated the engine but
never called start(), so the __initial__ event was never enqueued and
activate_initial_state() would fail with InvalidStateValue.

Closes #544
The boolean expression combinators (custom_not, custom_and, custom_or,
build_custom_operator) called predicates synchronously. When predicates
were async, they returned unawaited coroutine objects which are always
truthy, causing `not` to always return False, `and` to skip evaluation,
and `or` to short-circuit incorrectly.

Each combinator now checks `isawaitable()` on predicate results and
returns a coroutine when needed, which CallbackWrapper.__call__ already
knows how to await.

Closes #535
The pre-commit hook was using ruff v0.8.1 while the lockfile had v0.15.0,
causing import sorting differences between local and CI.
- Add docstrings to empty async on_enter_state methods (S1186)
- Use await asyncio.sleep(0) in async test hooks to satisfy S7503
`allowed_events` returns events reachable from the current state but does
not evaluate `cond`/`unless` guards. The new `enabled_events()` method
evaluates conditions and returns only events that can actually fire.

It accepts `*args`/`**kwargs` forwarded to condition callbacks, works with
both sync and async engines, and treats condition exceptions as enabled
(permissive behavior).

Closes #520
@sonarqubecloud
Copy link

@fgmacedo fgmacedo merged commit 1f6013c into develop Feb 13, 2026
13 checks passed
@fgmacedo fgmacedo deleted the feat/enabled-events-520 branch February 13, 2026 18:54
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 95.55556% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.77%. Comparing base (1fd4b7e) to head (cec1b9a).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
statemachine/engines/async_.py 86.66% 1 Missing and 1 partial ⚠️
statemachine/engines/sync.py 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #559      +/-   ##
===========================================
- Coverage   100.00%   99.77%   -0.23%     
===========================================
  Files           25       25              
  Lines         1656     1748      +92     
  Branches       204      228      +24     
===========================================
+ Hits          1656     1744      +88     
- Misses           0        2       +2     
- Partials         0        2       +2     
Flag Coverage Δ
unittests 99.77% <95.55%> (-0.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checking if conditions are valid before going through the transition

1 participant

Comments