You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Subclassing a StateChart whose nested body has callbacks raises AttributeError on _callbacks #658
classBase(StateChart):
classc(State.Compound):
a=State(initial=True)
b=State(final=True)
go=a.to(b)
defon_enter_b(self):
passclassSub(Base):
pass# AttributeError: 'State' object has no attribute '_callbacks'
add_inherited reuses the sameState objects from the base class (cls.add_state(state.id, state)
over base.states), while _unpack_builders_callbacks consumes them destructively:
So the base class deletes the attribute, and the subclass reads it on the shared object and
crashes. It only triggers when a nested body actually declares a callback, which is why it has
gone unnoticed.
The _callbacks bag exists because NestedStateFactory has no owning class to bind to when the
nested body is evaluated, so it hands everything back for the metaclass to flatten afterwards. #657 removes that bag entirely, which removes this failure along with it. A narrower fix is to
stop mutating shared state: read _callbacks without deleting it, or give the subclass its own
copy of the inherited State.
Found by an adversarial review of #645, unrelated to that change.
When fixing: add a subclassing example to docs/statecharts.md or docs/models.md if none
covers inheritance with nested bodies, and add an entry to the open release notes.
Activity
fgmacedo commentedon Sep 13, 2026
Duplicate of #646, which reported this first and has the same reproduction. The mechanism analysis has been moved there.