Skip to content

Commit 9c490eb

Browse files
committed
style: more typing
Signed-off-by: Yves Bastide <[email protected]>
1 parent cb67524 commit 9c490eb

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

simpleflow/cli/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class OutputFormat(str, Enum):
5050
@app.command()
5151
def filter(
5252
ctx: typer.Context,
53-
domain: Annotated[str, typer.Argument(envvar="SWF_DOMAIN")],
53+
domain: Annotated[str, typer.Option(envvar="SWF_DOMAIN")],
5454
status: Annotated[Status, typer.Option("--status", "-s")] = Status.open,
5555
tag: str | None = None,
5656
workflow_id: str | None = None,
5757
workflow_type: str | None = None,
5858
workflow_type_version: str | None = None,
5959
close_status: CloseStatus | None = None,
60-
started_since: int = 1,
60+
started_since: Annotated[int, typer.Option("--started-since", "-n")] = 1,
6161
from_date: Annotated[datetime, typer.Option(formats=TIMESTAMP_FORMATS)] | None = None,
6262
to_date: Annotated[datetime, typer.Option(formats=TIMESTAMP_FORMATS)] | None = None,
6363
):

simpleflow/process/_named_mixin.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
from simpleflow import logger
88

99

10-
def with_state(state):
10+
def with_state(state: str):
1111
"""
1212
Decorator used to change the process name when changing state.
13-
:param state: new state
14-
:type state: str
1513
"""
1614

1715
def wrapper(method):
@@ -36,7 +34,7 @@ class NamedMixin:
3634
method explicitly if not the first parent)
3735
2- decorate your methods with "@with_state("my_state")"
3836
39-
You can optionnally expose some other attributes of your worker by defining
37+
You can optionally expose some other attributes of your worker by defining
4038
the "_named_mixin_properties" attribute to a list or tuple of fields you want
4139
to include in your process title. For instance:
4240
@@ -52,11 +50,11 @@ def __init__(self, *args, **kwargs):
5250
self.state = kwargs.get("state", "initializing")
5351

5452
@property
55-
def state(self):
53+
def state(self) -> str:
5654
return self._state
5755

5856
@state.setter
59-
def state(self, value):
57+
def state(self, value: str) -> None:
6058
self._state = value
6159
self.set_process_name()
6260

simpleflow/process/_supervisor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(
8686
self._args = arguments if arguments is not None else ()
8787
self._background = background
8888

89-
self._processes = {}
89+
self._processes: dict[int, psutil.Process] = {}
9090
self._terminating = False
9191

9292
super().__init__()
@@ -106,7 +106,7 @@ def start(self):
106106

107107
def _cleanup_worker_processes(self):
108108
# cleanup children
109-
to_remove = []
109+
to_remove: list[int] = []
110110
for pid, child in self._processes.items():
111111
try:
112112
name, status = child.name(), child.status()

simpleflow/swf/process/decider/base.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
from typing import Any
1818

1919
from simpleflow.swf.executor import Executor
20+
from simpleflow.swf.mapper.models.decision.base import Decision
2021
from simpleflow.swf.mapper.responses import Response
2122

2223

2324
class Decider(Supervisor):
2425
"""
2526
Decider.
26-
27-
:ivar _poller: decider poller.
28-
:type _poller: DeciderPoller
2927
"""
3028

29+
_poller: DeciderPoller
30+
3131
def __init__(self, poller, nb_children=None):
3232
self._poller = poller
3333
super().__init__(
@@ -74,15 +74,16 @@ def __init__(
7474
behind this is to limit operational burden by having a single service
7575
handling multiple workflows.
7676
77-
:param workflow_executors: executors handling workflow executions.
78-
:type workflow_executors: list[simpleflow.swf.executor.Executor]
77+
workflow_executors: executors handling workflow executions.
7978
8079
"""
8180
self.workflow_name = f"{','.join([ex.workflow_class.name for ex in workflow_executors])}"
8281

8382
# Maps a workflow's name to its definition.
8483
# Used to dispatch a decision task to the corresponding workflow.
85-
self._workflow_executors = {executor.workflow_class.name: executor for executor in workflow_executors}
84+
self._workflow_executors: dict[str, Executor] = {
85+
executor.workflow_class.name: executor for executor in workflow_executors
86+
}
8687

8788
if task_list:
8889
self.task_list = task_list
@@ -123,8 +124,6 @@ def name(self):
123124
"""
124125
The main purpose of this property is to find what workflow a decider
125126
handles.
126-
127-
:rtype: str
128127
"""
129128
if self.workflow_name:
130129
suffix = f"(workflow={self.workflow_name})"
@@ -148,7 +147,6 @@ def complete(
148147
:param token: task token.
149148
:param decisions: decisions, maybe with context.
150149
:param execution_context: None...
151-
:return: nothing.
152150
"""
153151
if isinstance(decisions, DecisionsAndContext):
154152
decisions, execution_context = (
@@ -158,7 +156,7 @@ def complete(
158156
return simpleflow.swf.mapper.actors.Decider.complete(self, token, decisions, execution_context)
159157

160158
@with_state("processing")
161-
def process(self, decision_response):
159+
def process(self, decision_response: Response) -> None:
162160
"""
163161
Take a PollForDecisionTask response object and try to complete the
164162
decision task, by calling self._complete() with the response token and
@@ -171,7 +169,7 @@ def process(self, decision_response):
171169
spawn(self, decision_response)
172170

173171
@with_state("deciding")
174-
def decide(self, decision_response):
172+
def decide(self, decision_response: Response) -> (list[Decision], DecisionsAndContext):
175173
"""
176174
Delegate the decision to the decider worker (which itself delegates to
177175
the executor).

0 commit comments

Comments
 (0)