37
37
import temporalio .workflow_service
38
38
from temporalio .workflow_service import RetryConfig , RPCError , RPCStatusCode , TLSConfig
39
39
40
- LocalParamType = TypeVar ("LocalParamType" )
41
- LocalReturnType = TypeVar ("LocalReturnType" )
42
- WorkflowClass = TypeVar ("WorkflowClass" )
43
- WorkflowReturnType = TypeVar ("WorkflowReturnType" )
44
- MultiParamSpec = ParamSpec ("MultiParamSpec" )
40
+ from .types import (
41
+ LocalReturnType ,
42
+ MethodAsyncNoParam ,
43
+ MethodAsyncSingleParam ,
44
+ MethodSyncOrAsyncNoParam ,
45
+ MethodSyncOrAsyncSingleParam ,
46
+ MultiParamSpec ,
47
+ ParamType ,
48
+ ReturnType ,
49
+ SelfType ,
50
+ )
45
51
46
52
47
53
class Client :
@@ -198,7 +204,7 @@ def data_converter(self) -> temporalio.converter.DataConverter:
198
204
@overload
199
205
async def start_workflow (
200
206
self ,
201
- workflow : Callable [[ WorkflowClass ], Awaitable [ WorkflowReturnType ] ],
207
+ workflow : MethodAsyncNoParam [ SelfType , ReturnType ],
202
208
* ,
203
209
id : str ,
204
210
task_queue : str ,
@@ -213,17 +219,15 @@ async def start_workflow(
213
219
header : Optional [Mapping [str , Any ]] = None ,
214
220
start_signal : Optional [str ] = None ,
215
221
start_signal_args : Iterable [Any ] = [],
216
- ) -> WorkflowHandle [WorkflowClass , WorkflowReturnType ]:
222
+ ) -> WorkflowHandle [SelfType , ReturnType ]:
217
223
...
218
224
219
225
# Overload for single-param workflow
220
226
@overload
221
227
async def start_workflow (
222
228
self ,
223
- workflow : Callable [
224
- [WorkflowClass , LocalParamType ], Awaitable [WorkflowReturnType ]
225
- ],
226
- arg : LocalParamType ,
229
+ workflow : MethodAsyncSingleParam [SelfType , ParamType , ReturnType ],
230
+ arg : ParamType ,
227
231
* ,
228
232
id : str ,
229
233
task_queue : str ,
@@ -238,15 +242,15 @@ async def start_workflow(
238
242
header : Optional [Mapping [str , Any ]] = None ,
239
243
start_signal : Optional [str ] = None ,
240
244
start_signal_args : Iterable [Any ] = [],
241
- ) -> WorkflowHandle [WorkflowClass , WorkflowReturnType ]:
245
+ ) -> WorkflowHandle [SelfType , ReturnType ]:
242
246
...
243
247
244
248
# Overload for multi-param workflow
245
249
@overload
246
250
async def start_workflow (
247
251
self ,
248
252
workflow : Callable [
249
- Concatenate [WorkflowClass , MultiParamSpec ], Awaitable [WorkflowReturnType ]
253
+ Concatenate [SelfType , MultiParamSpec ], Awaitable [ReturnType ]
250
254
],
251
255
* ,
252
256
args : Iterable [Any ],
@@ -263,7 +267,7 @@ async def start_workflow(
263
267
header : Optional [Mapping [str , Any ]] = None ,
264
268
start_signal : Optional [str ] = None ,
265
269
start_signal_args : Iterable [Any ] = [],
266
- ) -> WorkflowHandle [WorkflowClass , WorkflowReturnType ]:
270
+ ) -> WorkflowHandle [SelfType , ReturnType ]:
267
271
...
268
272
269
273
# Overload for string-name workflow
@@ -377,7 +381,7 @@ async def start_workflow(
377
381
@overload
378
382
async def execute_workflow (
379
383
self ,
380
- workflow : Callable [[ WorkflowClass ], Awaitable [ WorkflowReturnType ] ],
384
+ workflow : MethodAsyncNoParam [ SelfType , ReturnType ],
381
385
* ,
382
386
id : str ,
383
387
task_queue : str ,
@@ -392,17 +396,15 @@ async def execute_workflow(
392
396
header : Optional [Mapping [str , Any ]] = None ,
393
397
start_signal : Optional [str ] = None ,
394
398
start_signal_args : Iterable [Any ] = [],
395
- ) -> WorkflowReturnType :
399
+ ) -> ReturnType :
396
400
...
397
401
398
402
# Overload for single-param workflow
399
403
@overload
400
404
async def execute_workflow (
401
405
self ,
402
- workflow : Callable [
403
- [WorkflowClass , LocalParamType ], Awaitable [WorkflowReturnType ]
404
- ],
405
- arg : LocalParamType ,
406
+ workflow : MethodAsyncSingleParam [SelfType , ParamType , ReturnType ],
407
+ arg : ParamType ,
406
408
* ,
407
409
id : str ,
408
410
task_queue : str ,
@@ -417,15 +419,15 @@ async def execute_workflow(
417
419
header : Optional [Mapping [str , Any ]] = None ,
418
420
start_signal : Optional [str ] = None ,
419
421
start_signal_args : Iterable [Any ] = [],
420
- ) -> WorkflowReturnType :
422
+ ) -> ReturnType :
421
423
...
422
424
423
425
# Overload for multi-param workflow
424
426
@overload
425
427
async def execute_workflow (
426
428
self ,
427
429
workflow : Callable [
428
- Concatenate [WorkflowClass , MultiParamSpec ], Awaitable [WorkflowReturnType ]
430
+ Concatenate [SelfType , MultiParamSpec ], Awaitable [ReturnType ]
429
431
],
430
432
* ,
431
433
args : Iterable [Any ],
@@ -442,7 +444,7 @@ async def execute_workflow(
442
444
header : Optional [Mapping [str , Any ]] = None ,
443
445
start_signal : Optional [str ] = None ,
444
446
start_signal_args : Iterable [Any ] = [],
445
- ) -> WorkflowReturnType :
447
+ ) -> ReturnType :
446
448
...
447
449
448
450
# Overload for string-name workflow
@@ -546,14 +548,14 @@ def get_workflow_handle(
546
548
def get_workflow_handle_for (
547
549
self ,
548
550
workflow : Union [
549
- Callable [[ WorkflowClass , LocalParamType ], Awaitable [ WorkflowReturnType ] ],
550
- Callable [[ WorkflowClass ], Awaitable [ WorkflowReturnType ] ],
551
+ MethodAsyncNoParam [ SelfType , ReturnType ],
552
+ MethodAsyncSingleParam [ SelfType , Any , ReturnType ],
551
553
],
552
554
workflow_id : str ,
553
555
* ,
554
556
run_id : Optional [str ] = None ,
555
557
first_execution_run_id : Optional [str ] = None ,
556
- ) -> WorkflowHandle [WorkflowClass , WorkflowReturnType ]:
558
+ ) -> WorkflowHandle [SelfType , ReturnType ]:
557
559
"""Get a typed workflow handle to an existing workflow by its ID.
558
560
559
561
This is the same as :py:meth:`get_workflow_handle` but typed. Note, the
@@ -641,7 +643,7 @@ class ClientConfig(TypedDict, total=False):
641
643
type_hint_eval_str : bool
642
644
643
645
644
- class WorkflowHandle (Generic [WorkflowClass , WorkflowReturnType ]):
646
+ class WorkflowHandle (Generic [SelfType , ReturnType ]):
645
647
"""Handle for interacting with a workflow.
646
648
647
649
This is usually created via :py:meth:`Client.get_workflow_handle` or
@@ -714,7 +716,7 @@ def first_execution_run_id(self) -> Optional[str]:
714
716
"""
715
717
return self ._first_execution_run_id
716
718
717
- async def result (self , * , follow_runs : bool = True ) -> WorkflowReturnType :
719
+ async def result (self , * , follow_runs : bool = True ) -> ReturnType :
718
720
"""Wait for result of the workflow.
719
721
720
722
This will use :py:attr:`result_run_id` if present to base the result on.
@@ -772,10 +774,10 @@ async def result(self, *, follow_runs: bool = True) -> WorkflowReturnType:
772
774
type_hints ,
773
775
)
774
776
if not results :
775
- return cast (WorkflowReturnType , None )
777
+ return cast (ReturnType , None )
776
778
elif len (results ) > 1 :
777
779
warnings .warn (f"Expected single result, got { len (results )} " )
778
- return cast (WorkflowReturnType , results [0 ])
780
+ return cast (ReturnType , results [0 ])
779
781
elif event .HasField ("workflow_execution_failed_event_attributes" ):
780
782
fail_attr = event .workflow_execution_failed_event_attributes
781
783
# Follow execution
@@ -891,9 +893,7 @@ async def describe(
891
893
@overload
892
894
async def query (
893
895
self ,
894
- query : Callable [
895
- [WorkflowClass ], Union [Awaitable [LocalReturnType ], LocalReturnType ]
896
- ],
896
+ query : MethodSyncOrAsyncNoParam [SelfType , LocalReturnType ],
897
897
* ,
898
898
reject_condition : Optional [temporalio .common .QueryRejectCondition ] = None ,
899
899
) -> LocalReturnType :
@@ -903,11 +903,8 @@ async def query(
903
903
@overload
904
904
async def query (
905
905
self ,
906
- query : Callable [
907
- [WorkflowClass , LocalParamType ],
908
- Union [Awaitable [LocalReturnType ], LocalReturnType ],
909
- ],
910
- arg : LocalParamType ,
906
+ query : MethodSyncOrAsyncSingleParam [SelfType , ParamType , LocalReturnType ],
907
+ arg : ParamType ,
911
908
* ,
912
909
reject_condition : Optional [temporalio .common .QueryRejectCondition ] = None ,
913
910
) -> LocalReturnType :
@@ -918,7 +915,7 @@ async def query(
918
915
async def query (
919
916
self ,
920
917
query : Callable [
921
- Concatenate [WorkflowClass , MultiParamSpec ],
918
+ Concatenate [SelfType , MultiParamSpec ],
922
919
Union [Awaitable [LocalReturnType ], LocalReturnType ],
923
920
],
924
921
* ,
@@ -1005,16 +1002,16 @@ async def query(
1005
1002
@overload
1006
1003
async def signal (
1007
1004
self ,
1008
- signal : Callable [[ WorkflowClass ], Union [ Awaitable [ None ], None ] ],
1005
+ signal : MethodSyncOrAsyncNoParam [ SelfType , None ],
1009
1006
) -> None :
1010
1007
...
1011
1008
1012
1009
# Overload for single-param signal
1013
1010
@overload
1014
1011
async def signal (
1015
1012
self ,
1016
- signal : Callable [[ WorkflowClass , LocalParamType ], Union [ Awaitable [ None ], None ] ],
1017
- arg : LocalParamType ,
1013
+ signal : MethodSyncOrAsyncSingleParam [ SelfType , ParamType , None ],
1014
+ arg : ParamType ,
1018
1015
) -> None :
1019
1016
...
1020
1017
@@ -1023,7 +1020,7 @@ async def signal(
1023
1020
async def signal (
1024
1021
self ,
1025
1022
signal : Callable [
1026
- Concatenate [WorkflowClass , MultiParamSpec ], Union [Awaitable [None ], None ]
1023
+ Concatenate [SelfType , MultiParamSpec ], Union [Awaitable [None ], None ]
1027
1024
],
1028
1025
* ,
1029
1026
args : Iterable [Any ],
0 commit comments