NestedStateFactory.__new__ runs while the State.Compound / State.Parallel class body is
evaluated, which is before the owning statechart class exists. It has no cls, so it cannot do
the setattr that the top-level path does in StateMachineMetaclass.add_from_attributes.
Two documented differences follow from that, both introduced with the #643 fix in #645:
class ExplicitId(StateChart):
class shire(State.Compound):
bag_end = State(initial=True)
green_dragon = State(final=True)
visit_pub = Event(bag_end.to(green_dragon), id="pub.visit")
ExplicitId.events # ['pub.visit'] -- registered
sm.send("pub.visit") # works
ExplicitId.visit_pub # AttributeError -- the top level would bind this
class Placeholder(StateChart):
class shire(State.Compound):
bag_end = State(initial=True)
green_dragon = State(final=True)
visit_pub = bag_end.to(green_dragon)
knock = Event(name="Knock on the door")
Placeholder.knock # AttributeError -- at the top level it is a class attribute
Both are pinned by tests in tests/test_statechart_compound.py
(test_explicit_id_wins_over_the_attribute_name, test_transition_less_event_declares_nothing).
The fix is #657: the nested body stops translating and stashes its raw
declarations on the State, and the metaclass reads them from add_state, where it has both
cls and the owning state.
When fixing: remove the note at the end of the Event section in docs/events.md and the
"two differences from the top-level form remain" paragraph in docs/releases/3.2.2.md, invert
the two tests above, and add an entry to the open release notes.
NestedStateFactory.__new__runs while theState.Compound/State.Parallelclass body isevaluated, which is before the owning statechart class exists. It has no
cls, so it cannot dothe
setattrthat the top-level path does inStateMachineMetaclass.add_from_attributes.Two documented differences follow from that, both introduced with the #643 fix in #645:
Both are pinned by tests in
tests/test_statechart_compound.py(
test_explicit_id_wins_over_the_attribute_name,test_transition_less_event_declares_nothing).The fix is #657: the nested body stops translating and stashes its raw
declarations on the
State, and the metaclass reads them fromadd_state, where it has bothclsand the owning state.When fixing: remove the note at the end of the
Eventsection indocs/events.mdand the"two differences from the top-level form remain" paragraph in
docs/releases/3.2.2.md, invertthe two tests above, and add an entry to the open release notes.