@@ -226,7 +226,7 @@ def find_lcca(states: List[State]) -> "State | None":
226226
227227 def get_effective_target_states (self , transition : Transition ) -> OrderedSet [State ]:
228228 # TODO: Handle history states
229- return OrderedSet ([transition .target ])
229+ return OrderedSet ([transition .target ]) if transition . target else OrderedSet ()
230230
231231 def select_eventless_transitions (self , trigger_data : TriggerData ):
232232 """
@@ -484,10 +484,10 @@ def _enter_states( # noqa: C901
484484 ).put (donedata = donedata )
485485
486486 if grandparent and grandparent .parallel :
487- if all (child . final for child in grandparent .states ):
488- BoundEvent (f"done.state. { parent . id } " , _sm = self . sm , internal = True ). put (
489- donedata = donedata
490- )
487+ if all (self . is_in_final_state ( child ) for child in grandparent .states ):
488+ BoundEvent (
489+ f"done.state. { grandparent . id } " , _sm = self . sm , internal = True
490+ ). put ( donedata = donedata )
491491 return result
492492
493493 def compute_entry_set (
@@ -506,6 +506,8 @@ def compute_entry_set(
506506 for transition in transitions :
507507 # Process each target state of the transition
508508 for target_state in [transition .target ]:
509+ if target_state is None :
510+ continue
509511 info = StateTransition (
510512 transition = transition , target = target_state , source = transition .source
511513 )
@@ -575,7 +577,6 @@ def add_descendant_states_to_enter(
575577 else :
576578 states_to_enter .add (info )
577579 state = info .target
578- assert state
579580
580581 if state .parallel :
581582 for child_state in state .states :
@@ -662,3 +663,11 @@ def add_ancestor_states_to_enter(
662663 states_for_default_entry ,
663664 default_history_content ,
664665 )
666+
667+ def is_in_final_state (self , state : State ) -> bool :
668+ if state .is_compound :
669+ return any (s .final and s in self .sm .configuration for s in state .states )
670+ elif state .parallel :
671+ return all (self .is_in_final_state (s ) for s in state .states )
672+ else :
673+ return False
0 commit comments