Skip to content

Commit

Permalink
Furthur simplipy _create_state_instant only create state from class
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Nov 30, 2024
1 parent 989f995 commit c0ae010
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
12 changes: 3 additions & 9 deletions src/plumpy/base/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,9 @@ def _enter_next_state(self, next_state: State) -> None:
self._fire_state_event(StateEventHook.ENTERED_STATE, last_state)

def _create_state_instance(
self, state: Union[Hashable, Type[State]], *args: Any, **kwargs: Any
self, state_cls: type[State], *args: Any, **kwargs: Any
) -> State:
# build from state class
if inspect.isclass(state) and issubclass(state, State):
state_cls = state
else:
try:
state_cls = self.get_states_map()[cast(Hashable, state)] # pylint: disable=unsubscriptable-object
except KeyError:
raise ValueError(f"{state} is not a valid state")
if state_cls.LABEL not in self.get_states_map():
raise ValueError(f"{state_cls.LABEL} is not a valid state")

return state_cls(self, *args, **kwargs)
10 changes: 5 additions & 5 deletions src/plumpy/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ def on_finish(self, result: Any, successful: bool) -> None:
if successful:
validation_error = self.spec().outputs.validate(self.outputs)
if validation_error:
raise StateEntryFailed(process_states.ProcessState.FINISHED, result, False)
raise StateEntryFailed(process_states.Finished, result, False)

self.future().set_result(self.outputs)

Expand Down Expand Up @@ -1017,7 +1017,7 @@ def transition_failed(
if final_state == process_states.ProcessState.CREATED:
raise exception.with_traceback(trace)

self.transition_to(process_states.ProcessState.EXCEPTED, exception, trace)
self.transition_to(process_states.Excepted, exception, trace)

def pause(self, msg: Union[str, None] = None) -> Union[bool, futures.CancellableAction]:
"""Pause the process.
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def do_kill(_next_state: process_states.State) -> Any:
try:
# Ignore the next state
# __import__('ipdb').set_trace()
self.transition_to(process_states.ProcessState.KILLED, exception)
self.transition_to(process_states.Killed, exception)
return True
finally:
self._killing = None
Expand Down Expand Up @@ -1134,7 +1134,7 @@ def fail(self, exception: Optional[BaseException], trace_back: Optional[Tracebac
:param exception: The exception that caused the failure
:param trace_back: Optional exception traceback
"""
self.transition_to(process_states.ProcessState.EXCEPTED, exception, trace_back)
self.transition_to(process_states.Excepted, exception, trace_back)

def kill(self, msg: Optional[MessageType] = None) -> Union[bool, asyncio.Future]:
"""
Expand Down Expand Up @@ -1162,7 +1162,7 @@ def kill(self, msg: Optional[MessageType] = None) -> Union[bool, asyncio.Future]
self._state.interrupt(interrupt_exception)
return cast(futures.CancellableAction, self._interrupt_action)

self.transition_to(process_states.ProcessState.KILLED, msg)
self.transition_to(process_states.Killed, msg)
return True

@property
Expand Down

0 comments on commit c0ae010

Please sign in to comment.