def dispatch(self, state_change: StateChange) -> List[Event]:
        """ Apply the `state_change` in the current machine and return the
        resulting events.

        Args:
            state_change: An object representation of a state
            change.

        Return:
            A list of events produced by the state transition.
            It's the upper layer's responsibility to decided how to handle
            these events.
        """
        assert isinstance(state_change, StateChange)

        # the state objects must be treated as immutable, so make a copy of the
        # current state and pass the copy to the state machine to be modified.
        next_state = deepcopy(self.current_state)

        # update the current state by applying the change
        iteration = self.state_transition(
            next_state,
            state_change,
        )

        assert isinstance(iteration, TransitionResult)

        self.current_state = iteration.new_state
        events = iteration.events

        assert isinstance(self.current_state, (State, type(None)))
        assert all(isinstance(e, Event) for e in events)

        return events
def dispatch ( self , state_change : StateChange ) -> List [ Event ] : assert isinstance ( state_change , StateChange ) next_state = deepcopy ( self . current_state ) iteration = self . state_transition ( next_state , state_change , ) assert isinstance ( iteration , TransitionResult ) self . current_state = iteration . new_state events = iteration . events assert isinstance ( self . current_state , ( State , type ( None ) ) ) assert all ( isinstance ( e , Event ) for e in events ) return events
Apply the `state_change` in the current machine and return the
        resulting events.

        Args:
            state_change: An object representation of a state
            change.

        Return:
            A list of events produced by the state transition.
            It's the upper layer's responsibility to decided how to handle
            these events.