@@ -104,6 +104,8 @@ class QuerySetReader:
104
104
105
105
@property
106
106
def as_querylang (self ):
107
+ """Render as QueryLang parameters.
108
+ # noqa: DAR201"""
107
109
parameters = {
108
110
name : getattr (self , name ) for name in self ._init_kwargs_dict .keys ()
109
111
}
@@ -119,10 +121,10 @@ def _get_parameter(self, key: str, default: Any):
119
121
if getattr (self , 'queryset' , None ):
120
122
for q in self .queryset :
121
123
if (
122
- not q .disabled
123
- and self .__class__ .__name__ == q .name
124
- and q .priority > self ._priority
125
- and key in q .parameters
124
+ not q .disabled
125
+ and self .__class__ .__name__ == q .name
126
+ and q .priority > self ._priority
127
+ and key in q .parameters
126
128
):
127
129
ret = q .parameters [key ]
128
130
return dict (ret ) if isinstance (ret , Struct ) else ret
@@ -139,12 +141,28 @@ def __getattr__(self, name: str):
139
141
140
142
141
143
class DriverType (type (JAMLCompatible ), type ):
144
+ """A meta class representing a Driver
145
+
146
+ When a new Driver is created, it gets registered
147
+ """
148
+
142
149
def __new__ (cls , * args , ** kwargs ):
150
+ """Create and register a new class with this meta class.
151
+
152
+ :param *args: *args for super
153
+ :param **kwargs: **kwargs for super
154
+ :return: the newly registered class
155
+ """
143
156
_cls = super ().__new__ (cls , * args , ** kwargs )
144
157
return cls .register_class (_cls )
145
158
146
159
@staticmethod
147
160
def register_class (cls ):
161
+ """Register a class
162
+
163
+ :param cls: the class
164
+ :return: the class, after being registered
165
+ """
148
166
reg_cls_set = getattr (cls , '_registered_class' , set ())
149
167
if cls .__name__ not in reg_cls_set or getattr (cls , 'force_register' , False ):
150
168
wrap_func (cls , ['__init__' ], store_init_kwargs )
@@ -189,12 +207,17 @@ def attach(self, runtime: 'ZEDRuntime', *args, **kwargs) -> None:
189
207
190
208
@property
191
209
def req (self ) -> 'Request' :
192
- """Get the current (typed) request, shortcut to ``self.runtime.request``"""
210
+ """Get the current (typed) request, shortcut to ``self.runtime.request``
211
+ # noqa: DAR201
212
+ """
193
213
return self .runtime .request
194
214
195
215
@property
196
216
def partial_reqs (self ) -> Sequence ['Request' ]:
197
- """The collected partial requests under the current ``request_id`` """
217
+ """The collected partial requests under the current ``request_id``
218
+ # noqa: DAR401
219
+ # noqa: DAR201
220
+ """
198
221
if self .expect_parts > 1 :
199
222
return self .runtime .partial_requests
200
223
else :
@@ -205,27 +228,42 @@ def partial_reqs(self) -> Sequence['Request']:
205
228
206
229
@property
207
230
def expect_parts (self ) -> int :
208
- """The expected number of partial messages """
231
+ """The expected number of partial messages
232
+ # noqa: DAR201
233
+ """
209
234
return self .runtime .expect_parts
210
235
211
236
@property
212
237
def msg (self ) -> 'Message' :
213
- """Get the current request, shortcut to ``self.runtime.message``"""
238
+ """Get the current request, shortcut to ``self.runtime.message``
239
+ # noqa: DAR201
240
+ """
214
241
return self .runtime .message
215
242
216
243
@property
217
244
def queryset (self ) -> 'QueryLangSet' :
245
+ """
246
+ # noqa: DAR101
247
+ # noqa: DAR102
248
+ # noqa: DAR201
249
+ """
218
250
if self .msg :
219
251
return self .msg .request .queryset
220
252
else :
221
253
return []
222
254
223
255
@property
224
256
def logger (self ) -> 'JinaLogger' :
225
- """Shortcut to ``self.runtime.logger``"""
257
+ """Shortcut to ``self.runtime.logger``
258
+ # noqa: DAR201
259
+ """
226
260
return self .runtime .logger
227
261
228
262
def __call__ (self , * args , ** kwargs ) -> None :
263
+ """
264
+ # noqa: DAR102
265
+ # noqa: DAR101
266
+ """
229
267
raise NotImplementedError
230
268
231
269
def __eq__ (self , other ):
@@ -249,29 +287,33 @@ class RecursiveMixin(BaseDriver):
249
287
250
288
@property
251
289
def docs (self ):
290
+ """
291
+ # noqa: DAR102
292
+ # noqa: DAR201
293
+ """
252
294
if self .expect_parts > 1 :
253
295
return (d for r in reversed (self .partial_reqs ) for d in r .docs )
254
296
else :
255
297
return self .req .docs
256
298
257
299
def _apply_root (
258
- self ,
259
- docs : 'DocumentSet' ,
260
- field : str ,
261
- * args ,
262
- ** kwargs ,
300
+ self ,
301
+ docs : 'DocumentSet' ,
302
+ field : str ,
303
+ * args ,
304
+ ** kwargs ,
263
305
) -> None :
264
306
return self ._apply_all (docs , None , field , * args , ** kwargs )
265
307
266
308
# TODO(Han): probably want to publicize this, as it is not obvious for driver
267
309
# developer which one should be inherited
268
310
def _apply_all (
269
- self ,
270
- docs : 'DocumentSet' ,
271
- context_doc : 'Document' ,
272
- field : str ,
273
- * args ,
274
- ** kwargs ,
311
+ self ,
312
+ docs : 'DocumentSet' ,
313
+ context_doc : 'Document' ,
314
+ field : str ,
315
+ * args ,
316
+ ** kwargs ,
275
317
) -> None :
276
318
"""Apply function works on a list of docs, modify the docs in-place
277
319
@@ -283,6 +325,11 @@ def _apply_all(
283
325
"""
284
326
285
327
def __call__ (self , * args , ** kwargs ):
328
+ """Call the Driver.
329
+
330
+ :param *args: *args for ``_traverse_apply``
331
+ :param **kwargs: **kwargs for ``_traverse_apply``
332
+ """
286
333
self ._traverse_apply (self .docs , * args , ** kwargs )
287
334
288
335
def _traverse_apply (self , docs : 'DocumentSet' , * args , ** kwargs ) -> None :
@@ -326,10 +373,17 @@ class FastRecursiveMixin:
326
373
"""
327
374
328
375
def __call__ (self , * args , ** kwargs ):
376
+ """Traverse with _apply_all
377
+
378
+ :param *args: *args for ``_apply_all``
379
+ :param **kwargs: **kwargs for ``_apply_all``
380
+ """
329
381
self ._apply_all (self .docs , * args , ** kwargs )
330
382
331
383
@property
332
384
def docs (self ) -> 'DocumentSet' :
385
+ """The DocumentSet after applying the traversal
386
+ # noqa: DAR201"""
333
387
from ..types .sets import DocumentSet
334
388
335
389
if self .expect_parts > 1 :
@@ -386,7 +440,9 @@ def __init__(self, executor: Optional[str] = None,
386
440
387
441
@property
388
442
def exec (self ) -> 'AnyExecutor' :
389
- """the executor that to which the instance is attached"""
443
+ """the executor that to which the instance is attached
444
+ # noqa: DAR201
445
+ """
390
446
return self ._exec
391
447
392
448
@property
@@ -396,8 +452,8 @@ def exec_fn(self) -> Callable:
396
452
:return: the Callable to execute in the driver
397
453
"""
398
454
if (
399
- not self .msg .is_error
400
- or self .runtime .args .on_error_strategy < OnErrorStrategy .SKIP_EXECUTOR
455
+ not self .msg .is_error
456
+ or self .runtime .args .on_error_strategy < OnErrorStrategy .SKIP_EXECUTOR
401
457
):
402
458
return self ._exec_fn
403
459
else :
@@ -417,7 +473,7 @@ def attach(self, executor: 'AnyExecutor', *args, **kwargs) -> None:
417
473
else :
418
474
for c in executor .components :
419
475
if any (
420
- t .__name__ == self ._executor_name for t in type .mro (c .__class__ )
476
+ t .__name__ == self ._executor_name for t in type .mro (c .__class__ )
421
477
):
422
478
self ._exec = c
423
479
break
0 commit comments