Skip to content

Commit a491469

Browse files
authored
Type-hinting improvements (#104)
* Type-hinting improvements
1 parent 1939eea commit a491469

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
CHANGED
11+
12+
- Add/update type-hinting for various worker methods
13+
814
## v1.2.0
915

1016
ADDED:

durabletask/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ def purge_orchestration(self, instance_id: str, recursive: bool = True):
230230
self._logger.info(f"Purging instance '{instance_id}'.")
231231
self._stub.PurgeInstances(req)
232232

233-
def signal_entity(self, entity_instance_id: EntityInstanceId, operation_name: str, input: Optional[Any] = None):
233+
def signal_entity(self,
234+
entity_instance_id: EntityInstanceId,
235+
operation_name: str,
236+
input: Optional[Any] = None) -> None:
234237
req = pb.SignalEntityRequest(
235238
instanceId=str(entity_instance_id),
236239
name=operation_name,

durabletask/task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def call_activity(self, activity: Union[Activity[TInput, TOutput], str], *,
142142
def call_entity(self,
143143
entity: EntityInstanceId,
144144
operation: str,
145-
input: Optional[TInput] = None) -> CompletableTask:
145+
input: Optional[TInput] = None) -> CompletableTask[Any]:
146146
"""Schedule entity function for execution.
147147
148148
Parameters
@@ -538,8 +538,8 @@ def task_id(self) -> int:
538538
return self._task_id
539539

540540

541-
# Orchestrators are generators that yield tasks and receive/return any type
542-
Orchestrator = Callable[[OrchestrationContext, TInput], Union[Generator[Task, Any, Any], TOutput]]
541+
# Orchestrators are generators that yield tasks, receive any type, and return TOutput
542+
Orchestrator = Callable[[OrchestrationContext, TInput], Union[Generator[Task[Any], Any, TOutput], TOutput]]
543543

544544
# Activities are simple functions that can be scheduled by orchestrators
545545
Activity = Callable[[ActivityContext, TInput], TOutput]

durabletask/worker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,42 +150,42 @@ def __init__(self):
150150
self.entities = {}
151151
self.entity_instances = {}
152152

153-
def add_orchestrator(self, fn: task.Orchestrator) -> str:
153+
def add_orchestrator(self, fn: task.Orchestrator[TInput, TOutput]) -> str:
154154
if fn is None:
155155
raise ValueError("An orchestrator function argument is required.")
156156

157157
name = task.get_name(fn)
158158
self.add_named_orchestrator(name, fn)
159159
return name
160160

161-
def add_named_orchestrator(self, name: str, fn: task.Orchestrator) -> None:
161+
def add_named_orchestrator(self, name: str, fn: task.Orchestrator[TInput, TOutput]) -> None:
162162
if not name:
163163
raise ValueError("A non-empty orchestrator name is required.")
164164
if name in self.orchestrators:
165165
raise ValueError(f"A '{name}' orchestrator already exists.")
166166

167167
self.orchestrators[name] = fn
168168

169-
def get_orchestrator(self, name: str) -> Optional[task.Orchestrator]:
169+
def get_orchestrator(self, name: str) -> Optional[task.Orchestrator[Any, Any]]:
170170
return self.orchestrators.get(name)
171171

172-
def add_activity(self, fn: task.Activity) -> str:
172+
def add_activity(self, fn: task.Activity[TInput, TOutput]) -> str:
173173
if fn is None:
174174
raise ValueError("An activity function argument is required.")
175175

176176
name = task.get_name(fn)
177177
self.add_named_activity(name, fn)
178178
return name
179179

180-
def add_named_activity(self, name: str, fn: task.Activity) -> None:
180+
def add_named_activity(self, name: str, fn: task.Activity[TInput, TOutput]) -> None:
181181
if not name:
182182
raise ValueError("A non-empty activity name is required.")
183183
if name in self.activities:
184184
raise ValueError(f"A '{name}' activity already exists.")
185185

186186
self.activities[name] = fn
187187

188-
def get_activity(self, name: str) -> Optional[task.Activity]:
188+
def get_activity(self, name: str) -> Optional[task.Activity[Any, Any]]:
189189
return self.activities.get(name)
190190

191191
def add_entity(self, fn: task.Entity) -> str:
@@ -362,7 +362,7 @@ def __enter__(self):
362362
def __exit__(self, type, value, traceback):
363363
self.stop()
364364

365-
def add_orchestrator(self, fn: task.Orchestrator) -> str:
365+
def add_orchestrator(self, fn: task.Orchestrator[TInput, TOutput]) -> str:
366366
"""Registers an orchestrator function with the worker."""
367367
if self._is_running:
368368
raise RuntimeError(
@@ -1047,7 +1047,7 @@ def call_entity(
10471047
entity: EntityInstanceId,
10481048
operation: str,
10491049
input: Optional[TInput] = None,
1050-
) -> task.CompletableTask:
1050+
) -> task.CompletableTask[Any]:
10511051
id = self.next_sequence_number()
10521052

10531053
self.call_entity_function_helper(

0 commit comments

Comments
 (0)