Skip to content

Commit

Permalink
mypy run (#541)
Browse files Browse the repository at this point in the history
* Hint init properties

Signed-off-by: liamhuber <[email protected]>

* Hint local function

Signed-off-by: liamhuber <[email protected]>

* Add stricter return and hint

Signed-off-by: liamhuber <[email protected]>

* 🐛 Hint tuple[] not ()

Signed-off-by: liamhuber <[email protected]>

* Black

Signed-off-by: liamhuber <[email protected]>

---------

Signed-off-by: liamhuber <[email protected]>
  • Loading branch information
liamhuber authored Jan 11, 2025
1 parent fc41dfa commit ff6a984
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pyiron_workflow/mixin/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import contextlib
from abc import ABC, abstractmethod
from collections.abc import Callable
from concurrent.futures import Executor as StdLibExecutor
from concurrent.futures import Future, ThreadPoolExecutor
from functools import partial
Expand Down Expand Up @@ -51,14 +52,14 @@ class Runnable(UsesState, HasLabel, HasRun, ABC):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.running = False
self.failed = False
self.executor = None
# We call it an executor, but it's just whether to use one.
# This is a simply stop-gap as we work out more sophisticated ways to reference
# (or create) an executor process without ever trying to pickle a `_thread.lock`
self.running: bool = False
self.failed: bool = False
self.executor: (
StdLibExecutor | tuple[Callable[..., StdLibExecutor], tuple, dict] | None
) = None
# We call it an executor, but it can also be instructions on making one
self.future: None | Future = None
self._thread_pool_sleep_time = 1e-6
self._thread_pool_sleep_time: float = 1e-6

@abstractmethod
def on_run(self, *args, **kwargs) -> Any: # callable[..., Any | tuple]:
Expand Down Expand Up @@ -135,7 +136,7 @@ def run(
:attr:`running`. (Default is True.)
"""

def _none_to_dict(inp):
def _none_to_dict(inp: dict | None) -> dict:
return {} if inp is None else inp

before_run_kwargs = _none_to_dict(before_run_kwargs)
Expand Down Expand Up @@ -275,7 +276,7 @@ def _finish_run(
run_exception_kwargs: dict,
run_finally_kwargs: dict,
**kwargs,
) -> Any | tuple:
) -> Any | tuple | None:
"""
Switch the status, then process and return the run result.
"""
Expand All @@ -288,6 +289,7 @@ def _finish_run(
self._run_exception(**run_exception_kwargs)
if raise_run_exceptions:
raise e
return None
finally:
self._run_finally(**run_finally_kwargs)

Expand All @@ -308,7 +310,7 @@ def _readiness_error_message(self) -> str:

@staticmethod
def _parse_executor(
executor: StdLibExecutor | (callable[..., StdLibExecutor], tuple, dict),
executor: StdLibExecutor | tuple[Callable[..., StdLibExecutor], tuple, dict],
) -> StdLibExecutor:
"""
If you've already got an executor, you're done. But if you get callable and
Expand Down

0 comments on commit ff6a984

Please sign in to comment.