11from datetime import datetime
22from inspect import BoundArguments
33from types import MappingProxyType
4- from typing import Any , Callable , Mapping , Protocol , Type
4+ from typing import Any , Callable , Iterable , Mapping , ParamSpec , Protocol , runtime_checkable
5+
6+ from typing_extensions import TypeVar
57
68from omnipy .api .enums import (OutputStorageProtocolOptions ,
79 PersistOutputsOptions ,
1921 TaskTemplateCovT ,
2022 TaskTemplateT )
2123
24+ CallP = ParamSpec ('CallP' )
25+ RetCovT = TypeVar ('RetCovT' , covariant = True )
26+ RetContraT = TypeVar ('RetContraT' , contravariant = True )
27+
2228
23- class IsJobBase (CanLog , IsUniquelyNamedJob , Protocol ):
29+ class IsJobBase (CanLog , IsUniquelyNamedJob , Protocol [ JobTemplateT , JobT , CallP , RetCovT ] ):
2430 """"""
2531 @property
2632 def _job_creator (self ) -> IsJobCreator :
@@ -38,68 +44,81 @@ def engine(self) -> IsEngine | None:
3844 def in_flow_context (self ) -> bool :
3945 ...
4046
41- def __eq__ (self , other : object ):
47+ def __eq__ (self , other : object ) -> bool :
4248 ...
4349
4450 @classmethod
45- def _create_job_template (cls , * args : object , ** kwargs : object ) -> 'IsJobTemplate' :
51+ def _create_job_template (cls , * args : object , ** kwargs : object ) -> JobTemplateT :
4652 ...
4753
4854 @classmethod
49- def _create_job (cls , * args : object , ** kwargs : object ) -> 'IsJob' :
55+ def _create_job (cls , * args : object , ** kwargs : object ) -> JobT :
56+ ...
57+
58+ def _apply (self ) -> JobT :
5059 ...
5160
52- def _apply (self ) -> 'IsJob' :
61+ def _refine (self , * args : Any , update : bool = True , ** kwargs : object ) -> JobTemplateT :
5362 ...
5463
55- def _refine (self , * args : Any , update : bool = True , ** kwargs : object ) -> 'IsJobTemplate' :
64+ def _revise (self ) -> JobTemplateT :
5665 ...
5766
58- def _revise (self ) -> 'IsJobTemplate' :
67+ def _call_job_template (self , * args : CallP . args , ** kwargs : CallP . kwargs ) -> RetCovT :
5968 ...
6069
61- def _call_job_template (self , * args : object , ** kwargs : object ) -> object :
70+ def _call_job (self , * args : CallP . args , ** kwargs : CallP . kwargs ) -> RetCovT :
6271 ...
6372
64- def _call_job (self , * args : object , ** kwargs : object ) -> object :
73+
74+ class IsJobBaseCallable (IsJobBase [JobTemplateT , JobT , CallP , RetCovT ],
75+ Protocol [JobTemplateT , JobT , CallP , RetCovT ]):
76+ def __call__ (self , * args : CallP .args , ** kwargs : CallP .kwargs ) -> RetCovT :
6577 ...
6678
6779
68- class IsJob (IsJobBase , Protocol ):
80+ @runtime_checkable
81+ class IsJob (IsJobBaseCallable [JobTemplateT , JobT , CallP , RetCovT ],
82+ Protocol [JobTemplateT , JobT , CallP , RetCovT ]):
6983 """"""
7084 @property
7185 def time_of_cur_toplevel_flow_run (self ) -> datetime | None :
7286 ...
7387
7488 @classmethod
75- def create_job (cls , * args : object , ** kwargs : object ) -> 'IsJob' :
89+ def create_job (cls , * args : object , ** kwargs : object ) -> JobT :
7690 ...
7791
78- def __call__ (self , * args : object , ** kwargs : object ) -> object :
92+ def revise (self ) -> JobTemplateT :
7993 ...
8094
8195 def _apply_engine_decorator (self , engine : IsEngine ) -> None :
8296 ...
8397
8498
85- class IsJobTemplate (IsJobBase , Protocol ):
99+ @runtime_checkable
100+ class IsJobTemplate (IsJobBaseCallable [JobTemplateT , JobT , CallP , RetCovT ],
101+ Protocol [JobTemplateT , JobT , CallP , RetCovT ]):
86102 """"""
87103 @classmethod
88- def create_job_template (cls , * args : object , ** kwargs : object ) -> 'IsJobTemplate' :
104+ def create_job_template (cls , * args : object , ** kwargs : object ) -> JobTemplateT :
105+ ...
106+
107+ def run (self , * args : CallP .args , ** kwargs : CallP .kwargs ) -> RetCovT :
89108 ...
90109
91- def run (self , * args : object , ** kwargs : object ) -> object :
110+ def apply (self ) -> JobT :
92111 ...
93112
94113
95- class IsFuncArgJobBase (IsJob , Protocol ):
114+ class IsFuncArgJobBase (Protocol ):
96115 """"""
97116 @property
98117 def param_signatures (self ) -> MappingProxyType :
99118 ...
100119
101120 @property
102- def return_type (self ) -> Type [ object ] :
121+ def return_type (self ) -> type :
103122 ...
104123
105124 @property
@@ -161,26 +180,25 @@ def get_bound_args(self, *args: object, **kwargs: object) -> BoundArguments:
161180 ...
162181
163182
183+ # Change?
164184class IsPlainFuncArgJobBase (Protocol ):
165185 """"""
186+
166187 _job_func : Callable
167188
168189 def _accept_call_func_decorator (self , call_func_decorator : GeneralDecorator ) -> None :
169190 ...
170191
171192
172- class IsFuncArgJob (IsFuncArgJobBase , Protocol [JobT ]):
173- """"""
174- def revise (self ) -> JobT :
175- ...
193+ CallableT = TypeVar ('CallableT' , bound = Callable )
176194
177195
178- class IsFuncArgJobTemplateCallable (Protocol [
179- JobTemplateT ,
180- ]):
196+ class HasFuncArgJobTemplateInit (Protocol [JobTemplateT , CallP , RetContraT ]):
181197 """"""
182198 def __call__ (
183199 self ,
200+ job_func : Callable [CallP , RetContraT ],
201+ * ,
184202 name : str | None = None ,
185203 iterate_over_data_files : bool = False ,
186204 output_dataset_param : str | None = None ,
@@ -189,14 +207,16 @@ def __call__(
189207 persist_outputs : PersistOutputsOptions | None = None ,
190208 restore_outputs : RestoreOutputsOptions | None = None ,
191209 result_key : str | None = None ,
192- fixed_params : Mapping [str , object ] | None = None ,
193- param_key_map : Mapping [str , str ] | None = None ,
210+ fixed_params : Mapping [str , object ] | Iterable [ tuple [ str , object ]] | None = None ,
211+ param_key_map : Mapping [str , str ] | Iterable [ tuple [ str , str ]] | None = None ,
194212 ** kwargs : object ,
195- ) -> Callable [[ Callable ], JobTemplateT ] :
213+ ) -> JobTemplateT :
196214 ...
197215
198216
199- class IsFuncArgJobTemplate (IsJobTemplate , IsFuncArgJobBase , Protocol [JobTemplateT , JobT ]):
217+ class IsFuncArgJobTemplate (IsJobTemplate [JobTemplateT , JobT , CallP , RetCovT ],
218+ IsFuncArgJobBase ,
219+ Protocol [JobTemplateT , JobT , CallP , RetCovT ]):
200220 """"""
201221 def refine (self ,
202222 * args : Any ,
@@ -209,13 +229,16 @@ def refine(self,
209229 persist_outputs : PersistOutputsOptions | None = None ,
210230 restore_outputs : RestoreOutputsOptions | None = None ,
211231 result_key : str | None = None ,
212- fixed_params : Mapping [str , object ] | None = None ,
213- param_key_map : Mapping [str , str ] | None = None ,
232+ fixed_params : Mapping [str , object ] | Iterable [ tuple [ str , object ]] | None = None ,
233+ param_key_map : Mapping [str , str ] | Iterable [ tuple [ str , str ]] | None = None ,
214234 ** kwargs : object ) -> JobTemplateT :
215235 ...
216236
217- def apply (self ) -> JobT :
218- ...
237+
238+ class IsFuncArgJob (IsJob [JobTemplateT , JobT , CallP , RetCovT ],
239+ IsFuncArgJobBase ,
240+ Protocol [JobTemplateT , JobT , CallP , RetCovT ]):
241+ """"""
219242
220243
221244class IsTaskTemplateArgsJobBase (IsFuncArgJobBase , Protocol [TaskTemplateCovT ]):
@@ -226,15 +249,20 @@ def task_templates(self) -> tuple[TaskTemplateCovT, ...]:
226249
227250
228251class IsTaskTemplateArgsJob (IsTaskTemplateArgsJobBase [TaskTemplateCovT ],
229- IsFuncArgJob [JobT ],
230- Protocol [TaskTemplateCovT , JobT ]):
252+ IsFuncArgJob [JobTemplateT , JobT , CallP , RetCovT ],
253+ Protocol [TaskTemplateCovT , JobTemplateT , JobT , CallP , RetCovT ]):
231254 """"""
232255
233256
234- class IsTaskTemplateArgsJobTemplateCallable (Protocol [TaskTemplateContraT , JobTemplateT ]):
257+ class HasTaskTemplateArgsJobTemplateInit (Protocol [JobTemplateT ,
258+ TaskTemplateContraT ,
259+ CallP ,
260+ RetContraT ]):
235261 """"""
236262 def __call__ (
237263 self ,
264+ job_func : Callable [CallP , RetContraT ],
265+ / ,
238266 * task_templates : TaskTemplateContraT ,
239267 name : str | None = None ,
240268 iterate_over_data_files : bool = False ,
@@ -244,16 +272,16 @@ def __call__(
244272 persist_outputs : PersistOutputsOptions | None = None ,
245273 restore_outputs : RestoreOutputsOptions | None = None ,
246274 result_key : str | None = None ,
247- fixed_params : Mapping [str , object ] | None = None ,
248- param_key_map : Mapping [str , str ] | None = None ,
275+ fixed_params : Mapping [str , object ] | Iterable [ tuple [ str , object ]] | None = None ,
276+ param_key_map : Mapping [str , str ] | Iterable [ tuple [ str , str ]] | None = None ,
249277 ** kwargs : object ,
250- ) -> Callable [[ Callable ], JobTemplateT ] :
278+ ) -> JobTemplateT :
251279 ...
252280
253281
254- class IsTaskTemplateArgsJobTemplate (IsFuncArgJobTemplate [JobTemplateT , JobT ],
282+ class IsTaskTemplateArgsJobTemplate (IsFuncArgJobTemplate [JobTemplateT , JobT , CallP , RetCovT ],
255283 IsTaskTemplateArgsJobBase [TaskTemplateT ],
256- Protocol [TaskTemplateT , JobTemplateT , JobT ]):
284+ Protocol [TaskTemplateT , JobTemplateT , JobT , CallP , RetCovT ]):
257285 """"""
258286 def refine (self ,
259287 * task_templates : TaskTemplateT ,
@@ -263,8 +291,8 @@ def refine(self,
263291 output_dataset_param : str | None = None ,
264292 output_dataset_cls : type [IsDataset ] | None = None ,
265293 auto_async : bool = True ,
266- fixed_params : Mapping [str , object ] | None = None ,
267- param_key_map : Mapping [str , str ] | None = None ,
294+ fixed_params : Mapping [str , object ] | Iterable [ tuple [ str , object ]] | None = None ,
295+ param_key_map : Mapping [str , str ] | Iterable [ tuple [ str , str ]] | None = None ,
268296 result_key : str | None = None ,
269297 persist_outputs : PersistOutputsOptions | None = None ,
270298 restore_outputs : RestoreOutputsOptions | None = None ,
0 commit comments