The documentation section Declaring events states that event can be declared with the Event class "for better IDE support (autocompletion, type checking) or to set a human-readable display name". It seems these advantages can not be used when the Event class is used inside the State.Compound class. When the event = Event(<transition>) form is used inside this class, the event is ignored, and <transition> becomes eventless.
I didn’t find any example in the documentation where events or transitions would be declared using the Event(<transition>) or event = Event(<transition>) forms inside the State.Compound class. However, I also didn’t find any restrictions regarding this.
Let's look at example from the Compound states section with and without Event(...) declaration.
The following snippet shows that these machines are not identical:
j = Journey()
qj = QuirkyJourney()
print("Journey SM:")
print(f" Configuration: {j.configuration}")
print(f" Enabled events: {j.enabled_events()}")
j._graph().write_png("j.png")
print("QuirkyJourney SM:")
print(f" Configuration: {qj.configuration}")
print(f" Enabled events: {qj.enabled_events()}")
qj._graph().write_png("qj.png")
Output:
Journey SM:
Configuration: {Shire, Bag end}
Enabled events: [BoundEvent('depart', delay=0, internal=False), BoundEvent('visit_pub', delay=0, internal=False)]
QuirkyJourney SM:
Configuration: {Shire, Green dragon}
Enabled events: [BoundEvent('depart', delay=0, internal=False)]
Images:
-
Journey SM:

-
QuirkyJourney SM:

As you can see, the qj transitions to the green_dragon state without receiving the visit_pub event.
I checked the given example with python-statemachine 3.0.0, 3.1.0, 3.2.0 and 3.2.1. All have the same behavior.
The documentation section Declaring events states that event can be declared with the
Eventclass "for better IDE support (autocompletion, type checking) or to set a human-readable display name". It seems these advantages can not be used when theEventclass is used inside theState.Compoundclass. When theevent = Event(<transition>)form is used inside this class, theeventis ignored, and<transition>becomes eventless.I didn’t find any example in the documentation where events or transitions would be declared using the
Event(<transition>)orevent = Event(<transition>)forms inside theState.Compoundclass. However, I also didn’t find any restrictions regarding this.Let's look at example from the Compound states section with and without
Event(...)declaration.The original example:
And the same example, but with events
visit_pubanddepartdeclared usingEvent(...):The following snippet shows that these machines are not identical:
Output:
Images:
Journey SM:

QuirkyJourney SM:

As you can see, the
qjtransitions to thegreen_dragonstate without receiving thevisit_pubevent.I checked the given example with python-statemachine 3.0.0, 3.1.0, 3.2.0 and 3.2.1. All have the same behavior.