Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: kwargs without unpacking #2158

Merged
merged 8 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion jina/clients/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def _get_results(
:param on_done: the callback for on_done
:param on_error: the callback for on_error
:param on_always: the callback for on_always
:param **kwargs: **kwargs for _get_task_name and _get_requests
:param kwargs: kwargs for _get_task_name and _get_requests
:yields: generator over results
"""
with ImportExtensions(required=True):
Expand Down
40 changes: 20 additions & 20 deletions jina/drivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class DriverType(type(JAMLCompatible), type):
def __new__(cls, *args, **kwargs):
"""Create and register a new class with this meta class.

:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
:return: the newly registered class
"""
_cls = super().__new__(cls, *args, **kwargs)
Expand Down Expand Up @@ -187,8 +187,8 @@ class BaseDriver(JAMLCompatible, metaclass=DriverType):

:param priority: the priority of its default arg values (hardcoded in Python). If the
received ``QueryLang`` has a higher priority, it will override the hardcoded value
:param *args: not used (kept to maintain interface)
:param **kwargs: not used (kept to maintain interface)
:param args: not used (kept to maintain interface)
:param kwargs: not used (kept to maintain interface)
"""

store_args_kwargs = False #: set this to ``True`` to save ``args`` (in a list) and ``kwargs`` (in a map) in YAML config
Expand All @@ -203,8 +203,8 @@ def attach(self, runtime: 'ZEDRuntime', *args, **kwargs) -> None:
"""Attach this driver to a :class:`jina.peapods.runtimes.zmq.zed.ZEDRuntime`

:param runtime: the pea to be attached
:param *args: not used (kept to maintain interface)
:param **kwargs: not used (kept to maintain interface)
:param args: not used (kept to maintain interface)
:param kwargs: not used (kept to maintain interface)
"""
self.runtime = runtime
self.attached = True
Expand Down Expand Up @@ -333,8 +333,8 @@ class ContextAwareRecursiveMixin:
def __call__(self, *args, **kwargs):
"""Traverse with _apply_all

:param *args: *args forwarded to ``_apply_all``
:param **kwargs: **kwargs forwarded to ``_apply_all``
:param args: args forwarded to ``_apply_all``
:param kwargs: kwargs forwarded to ``_apply_all``
"""
document_sets = self.docs.traverse(self._traversal_paths)
self._apply_all(document_sets, *args, **kwargs)
Expand All @@ -353,8 +353,8 @@ def _apply_all(
Adding a chunk to a ChunkSet results in adding a chunk to the parent Document.

:param doc_sequences: the Documents that should be handled
:param *args: driver specific arguments, which might be forwarded to the Executor
:param **kwargs: driver specific arguments, which might be forwarded to the Executor
:param args: driver specific arguments, which might be forwarded to the Executor
:param kwargs: driver specific arguments, which might be forwarded to the Executor
"""


Expand All @@ -372,8 +372,8 @@ class FlatRecursiveMixin:
def __call__(self, *args, **kwargs):
"""Traverse with _apply_all

:param *args: *args forwarded to ``_apply_all``
:param **kwargs: **kwargs forwarded to ``_apply_all``
:param args: args forwarded to ``_apply_all``
:param kwargs: kwargs forwarded to ``_apply_all``
"""
path_documents = self.docs.traverse_flattened_per_path(self._traversal_paths)
for documents in path_documents:
Expand All @@ -391,8 +391,8 @@ def _apply_all(
The list refers to all reachable leafes of a single ``traversal_path``.

:param docs: the Documents that should be handled
:param *args: driver specific arguments, which might be forwarded to the Executor
:param **kwargs: driver specific arguments, which might be forwarded to the Executor
:param args: driver specific arguments, which might be forwarded to the Executor
:param kwargs: driver specific arguments, which might be forwarded to the Executor

"""

Expand All @@ -407,8 +407,8 @@ def __init__(self, traversal_paths: Tuple[str] = ('c', 'r'), *args, **kwargs):
"""Initialize a :class:`BaseRecursiveDriver`

:param traversal_paths: Describes the leaves of the document tree on which _apply_all are called
:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""
super().__init__(*args, **kwargs)
self._traversal_paths = [path.lower() for path in traversal_paths]
Expand All @@ -434,8 +434,8 @@ def __init__(

:param executor: the name of the sub-executor, only necessary when :class:`jina.executors.compound.CompoundExecutor` is used
:param method: the function name of the executor that the driver feeds to
:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""
super().__init__(*args, **kwargs)
self._executor_name = executor
Expand Down Expand Up @@ -470,8 +470,8 @@ def attach(self, executor: 'AnyExecutor', *args, **kwargs) -> None:
"""Attach the driver to a :class:`jina.executors.BaseExecutor`

:param executor: the executor to which we attach
:param *args: *args for super().attach()
:param **kwargs: **kwargs for super().attach()
:param args: additional positional arguments for the call of super().attach()
:param kwargs: additional key value arguments for the call of super().attach()
"""
super().attach(*args, **kwargs)
if self._executor_name and isinstance(executor, CompoundExecutor):
Expand Down
8 changes: 4 additions & 4 deletions jina/drivers/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class BaseCacheDriver(BaseIndexDriver):
"""A driver related to :class:`BaseCache`.

:param with_serialization: feed serialized Document to the CacheIndexer
:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(self, with_serialization: bool = False, *args, **kwargs):
Expand Down Expand Up @@ -79,8 +79,8 @@ def __init__(self, tags: Dict, *args, **kwargs):
"""Create a new TaggingCacheDriver.

:param tags: the tags to be updated on hit docs
:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""
super().__init__(*args, **kwargs)
self._tags = tags
Expand Down
31 changes: 16 additions & 15 deletions jina/drivers/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ def envelope(self) -> 'jina_pb2.EnvelopeProto':


class LogInfoDriver(BaseControlDriver):
"""Log output the request info"""
"""
Log output the request info

:param key: (str) that represents a first level or nested key in the dict
:param json: (bool) indicating if the log output should be formatted as json
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(self, key: str = 'request', json: bool = True, *args, **kwargs):
"""
:param key: (str) that represents a first level or nested key in the dict
:param json: (bool) indicating if the log output should be formatted as json
:param *args: *args for super
:param **kwargs: **kwargs for super
"""
super().__init__(*args, **kwargs)
self.key = key
self.json = json

def __call__(self, *args, **kwargs):
"""Log the information.

:param *args: unused
:param **kwargs: unused
:param args: unused
:param kwargs: unused
"""
data = dunder_get(self.msg.proto, self.key)
if self.json:
Expand All @@ -70,8 +71,8 @@ class ControlReqDriver(BaseControlDriver):
def __call__(self, *args, **kwargs):
"""Handle the request controlling.

:param *args: unused
:param **kwargs: unused
:param args: unused
:param kwargs: unused
"""
if self.req.command == 'TERMINATE':
self.envelope.status.code = jina_pb2.StatusProto.SUCCESS
Expand All @@ -98,8 +99,8 @@ class RouteDriver(ControlReqDriver):
mark it in the envelope if it is a control request in

:param raise_no_dealer: raise a RuntimeError when no available dealer
:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(self, raise_no_dealer: bool = False, *args, **kwargs):
Expand All @@ -111,8 +112,8 @@ def __init__(self, raise_no_dealer: bool = False, *args, **kwargs):
def __call__(self, *args, **kwargs):
"""Perform the routing.

:param *args: *args for super().__call__
:param **kwargs: **kwargs for super().__call__
:param args: additional positional arguments wich are just used for calling the parent
:param kwargs: additional key value arguments wich are just used for calling the parent


.. # noqa: DAR401
Expand Down
4 changes: 2 additions & 2 deletions jina/drivers/convertdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ConvertDriver(FlatRecursiveMixin, BaseRecursiveDriver):
def __init__(self, convert_fn: str, *args, **kwargs):
"""
:param convert_fn: the method name from `:class:`Document` to be applied
:param *args: *args for super
:param **kwargs: the set of named arguments to be passed to `convert_fn`
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: the set of named arguments to be passed to `convert_fn`
"""
super().__init__(*args, **kwargs)
self._convert_fn = convert_fn
Expand Down
4 changes: 2 additions & 2 deletions jina/drivers/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __call__(self, *args, **kwargs):
"""
Call base executable driver on document ids for deletion.

:param args: Additional positional arguments
:param kwargs: Additional keyword arguments
:param args: unused
:param kwargs: unused
"""
self.exec_fn(self.req.ids)
16 changes: 8 additions & 8 deletions jina/drivers/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class BaseEvaluateDriver(BaseExecutableDriver):
:param executor: the name of the sub-executor, only necessary when :class:`jina.executors.compound.CompoundExecutor` is used
:param method: the function name of the executor that the driver feeds to
:param running_avg: always return running average instead of value of the current run
:param *args:
:param **kwargs:
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(
Expand All @@ -44,8 +44,8 @@ def __init__(
def __call__(self, *args, **kwargs):
"""Load the ground truth pairs.

:param *args: *args for _traverse_apply
:param **kwargs: **kwargs for _traverse_apply
:param args: args for _traverse_apply
:param kwargs: kwargs for _traverse_apply
"""
docs_groundtruths = DocumentGroundtruthSequence(
[
Expand Down Expand Up @@ -93,8 +93,8 @@ class FieldEvaluateDriver(BaseEvaluateDriver):
Evaluate on the values from certain field, the extraction is implemented with :meth:`dunder_get`.

:param field: the field name to be extracted from the Protobuf.
:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(self, field: str, *args, **kwargs):
Expand All @@ -120,8 +120,8 @@ class RankEvaluateDriver(BaseEvaluateDriver):
The differences with `:class:FieldEvaluateDriver` are:
- More than one field is allowed. For instance, for NDCGComputation you may need to have both `ID` and `Relevance` information.
- The fields are extracted from the `matches` of the `Documents` and the `Groundtruth` so it returns a sequence of values.
:param *args:
:param **kwargs:
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

@deprecated_alias(field=('fields', 0))
Expand Down
4 changes: 2 additions & 2 deletions jina/drivers/multimodal.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def _apply_all(self, docs: 'DocumentSet', *args, **kwargs) -> None:
"""Apply the driver to each of the Documents in docs.

:param docs: the docs for which a ``multimodal embedding`` will be computed, whose chunks are of different
:param *args: args
:param **kwargs: kwargs
:param args: unused
:param kwargs: unused
"""
content_by_modality = defaultdict(
list
Expand Down
22 changes: 9 additions & 13 deletions jina/drivers/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class BasePredictDriver(FlatRecursiveMixin, BaseExecutableDriver):
"""Drivers inherited from :class:`BasePredictDriver` will bind :meth:`predict` by default

:param fields: name of fields to be used to predict tags, default "embeddings"
:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(
Expand All @@ -33,8 +33,8 @@ class BaseLabelPredictDriver(BasePredictDriver):
"""Base class of a Driver for label prediction.

:param output_tag: output label will be written to ``doc.tags``
:param *args: *args for super
:param **kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(self, output_tag: str = 'prediction', *args, **kwargs):
Expand Down Expand Up @@ -84,19 +84,15 @@ def prediction2label(self, prediction: 'np.ndarray') -> List[Any]:


class BinaryPredictDriver(BaseLabelPredictDriver):
"""Converts binary prediction into string label.
"""Converts binary prediction into string label. This is often used with binary classifier.

This is often used with binary classifier.
:param one_label: label when prediction is one
:param zero_label: label when prediction is zero
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(self, one_label: str = 'yes', zero_label: str = 'no', *args, **kwargs):
"""

:param one_label: label when prediction is one
:param zero_label: label when prediction is zero
:param *args: *args for super
:param **kwargs: **kwargs for super
"""
super().__init__(*args, **kwargs)
self.one_label = one_label
self.zero_label = zero_label
Expand Down
4 changes: 2 additions & 2 deletions jina/drivers/querylang/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class FilterQL(QuerySetReader, ContextAwareRecursiveMixin, BaseRecursiveDriver):
:param lookups: (dict) a dictionary where keys are interpreted by ``:class:`LookupLeaf`` to form a
an evaluation function. For instance, a dictionary ``{ modality__in: [mode1, mode2] }``, would create
an evaluation function that will check if the field `modality` is found in `[mode1, mode2]`
:param *args: *args for super
:param *kwargs: **kwargs for super
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(self, lookups: Dict[str, Any], *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions jina/drivers/querylang/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class ExcludeQL(QuerySetReader, FlatRecursiveMixin, BaseRecursiveDriver):

:param fields: the pruned field names in tuple
:param traversal_paths: the traversal paths
:param *args: *args
:param **kwargs: **kwargs
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(
Expand Down
16 changes: 7 additions & 9 deletions jina/drivers/querylang/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@ class SliceQL(QuerySetReader, ContextAwareRecursiveMixin, BaseRecursiveDriver):
traversal_paths: ['m']

`SliceQL` will ensure that only the first 50 documents are returned from this `Pod`

:param start: Zero-based index at which to start extraction.
:param end: Zero-based index before which to end extraction.
slice extracts up to but not including end. For example, take(1,4) extracts
the second element through the fourth element (elements indexed 1, 2, and 3).
:param args: additional positional arguments wich are just used for the parent initialization
:param kwargs: additional key value arguments wich are just used for the parent initialization
"""

def __init__(self, start: int, end: Optional[int] = None, *args, **kwargs):
"""

:param start: Zero-based index at which to start extraction.
:param end: Zero-based index before which to end extraction.
slice extracts up to but not including end. For example, take(1,4) extracts
the second element through the fourth element (elements indexed 1, 2, and 3).
:param *args: *args for super
:param **kwargs: **kwargs for super
"""
super().__init__(*args, **kwargs)
self._start = int(start)
if end is None:
Expand Down