diff --git a/src/plumpy/base/state_machine.py b/src/plumpy/base/state_machine.py index 499612e0..853ca668 100644 --- a/src/plumpy/base/state_machine.py +++ b/src/plumpy/base/state_machine.py @@ -312,7 +312,7 @@ def _fire_state_event(self, hook: Hashable, state: Optional[State]) -> None: def on_terminated(self) -> None: """Called when a terminal state is entered""" - def transition_to(self, new_state: Union[State, Type[State]], **kwargs: Any) -> None: + def transition_to(self, new_state: State | type[State] | None, **kwargs: Any) -> None: """Transite to the new state. The new target state will be create lazily when the state is not yet instantiated, @@ -322,6 +322,9 @@ def transition_to(self, new_state: Union[State, Type[State]], **kwargs: Any) -> """ assert not self._transitioning, 'Cannot call transition_to when already transitioning state' + if new_state is None: + return None + initial_state_label = self._state.LABEL if self._state is not None else None label = None try: