Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #694 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 53 54 +1
Lines 5900 5959 +59
Branches 939 952 +13
=========================================
+ Hits 5900 5959 +59
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
fgmacedo
force-pushed
the
fgmacedo/uml-w2c_initial
branch
from
October 15, 2026 00:54
e2abeb3 to
c5d1039
Compare
fgmacedo
force-pushed
the
fgmacedo/uml-w2c_initial
branch
from
October 15, 2026 01:56
c5d1039 to
0ad7a1d
Compare
A method named on_init_<state>() is resolved as an action of the state's initial transition, explicit or by document order. It runs after the state's enter callbacks and only on default entry, giving the UML statechart init action a callback convention. Closes #587 Signed-off-by: Fernando Macedo <fgmacedo@gmail.com>
fgmacedo
force-pushed
the
fgmacedo/uml-w2c_initial
branch
from
October 16, 2026 22:21
0ad7a1d to
20cb9a8
Compare
A method named on_init_<state> is also the on_ action of an event named init_<state>, so it would run for both. The class build now finds those names once per class and checks the class, the model and every listener attached by the constructor or add_listener against them: on_init_ names raise InvalidDefinition, and the existing on_enter_, on_exit_ and on_invoke_ overlaps emit a DeprecationWarning until 4.0. validate_callback_name_conflicts = False opts out. Refs #587 Signed-off-by: Fernando Macedo <fgmacedo@gmail.com>
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes #587
Refs #692
Builds on #693 (merged), which makes default entry run the initial transition it chose.
Why
#587 asks for the UML "init" of a compound state: an initial transition that targets a nested descendant and runs an action.
d.to(d.d2.d21.d212, initial=True, on="init_action")entered the deep target, but the factory also registered the document-order initiald -> d1, so the state held two initial transitions andinit_actionnever ran. There was also no callback convention for it, which the issue thread promised ason_init_<state>().What changes
InvalidDefinition.on=action runs after the compound'sentercallbacks and before any child is entered, on every default entry (start, re-entry, history default), on sync and async engines.on_init_<state>(), on the chart or on a listener: runs as part of the compound's initial transition, explicit or by document order, after theon=action, and only on default entry. A transition that targets a descendant directly skips it. A parallel state never runs its own; its regions do.on_init_<state>()follow transitiononrules: in aStateChartthey becomeerror.executionand entry completes, instead of aborting the microstep.listeners = [...],add_listener()):on_init_<state>with an eventinit_<state>raisesInvalidDefinition; the existingon_enter_/on_exit_/on_invoke_overlaps (which already run twice onmain) emit aDeprecationWarningpointing at user code, to raise in 4.0. A rejected listener is not attached.validate_callback_name_conflicts = Falseopts out.InvalidDefinition.docs/states.md(doctests, including a root-level init by wrapping the states in a top compound), callback table indocs/actions.md, a new validation indocs/validations.md, and 3.3.0 release notes (feature, behavior change, deprecation, bug fix).tests/test_statechart_error.pyhad a real overlap (evententer_dangerwithon_enter_danger, so the handler ran twice); its event is renamed togo_danger.Evidence
timeout 120 uv run pytest tests/test_statechart_initial_transition.py: 28 passed (sync and async viasm_runner). Before this PR, 15 of the explicit-initial tests fail onmainand 8 of the 10on_init_cases fail without thetransition.pychange.d.to(d.d2, initial=True, on=...)andd2.to(d2.d21.d211, initial=True, on=...)printsd-ENTRY;d-INIT;d2-ENTRY;d2-INIT;d21-ENTRY;d211-ENTRY; transitionC: d2 -> d1printsd1-ENTRY;d1-INIT;d11-ENTRY.timeout 120 uv run pytest tests/test_callback_name_conflicts.py: 25 passed.timeit,PersonalityMachine): 2.5 µs per class build, 38 ns per listener check with no ambiguous name, against 54 µs to create an instance.timeout 300 uv run pytest -n 4 --cov=statemachine --cov-branch --cov-fail-under=100 -W "error:.*bound both:DeprecationWarning"onmainec5d817: 3028 passed, 26 skipped, 126 xfailed; coverage 100.00%. PSSM suite (tests/uml/pssm/,xfail_strict): 150 passed, 1 skipped, 82 xfailed, no case changes status. Pre-commit (ruff, mypy, pyright, pytest) passes.on_init_<state>): one material finding, theinit_<x>event name overlap, now rejected; doc wording nits fixed. Round 3 (name check): methods in nested state bodies escaped the check, anddeepcopy/picklewarned again; both fixed. Round 4: a rejected listener stayed inactive_listenersand came back on copy; fixed by checking before attaching. Round 5: nothing material. Verified OK there: ordering withon=and deep history targets, default-entry-only, parallel regions, errors onStateChartandStateMachine, subclasses, listeners added after start, SCXML ids with dots and dashes.Not verified
MachineMixin(Django models) or a user__init__override between the caller andStateMachine.__init__, theDeprecationWarningis attributed to library or intermediate frames, so Python's default filters may hide it outside pytest or-W.__init__(self.on_init_x = ...) are not checked.initial=Truechild; an initial target outside the compound is not validated (pre-existing).