From ab3f1431915b18e80827636f90f4a2e05bc7f48c Mon Sep 17 00:00:00 2001 From: Alexander Schlemmer <a.schlemmer@indiscale.com> Date: Tue, 21 May 2024 10:56:03 +0200 Subject: [PATCH] DOC: improved docstring of the _for_each helper function --- src/caoscrawler/sync_graph.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/caoscrawler/sync_graph.py b/src/caoscrawler/sync_graph.py index 36ed36d7..dc97f2c3 100644 --- a/src/caoscrawler/sync_graph.py +++ b/src/caoscrawler/sync_graph.py @@ -44,16 +44,24 @@ logger = logging.getLogger(__name__) def _for_each_scalar_value(node: SyncNode, condition: Callable[[Any], bool], kind: str, - value: Any = None): + value: Callable[[Any], Any] = None): """ helper function that performs an action on each value element of each property of a node - The action (remove or set) is performed on each property value of each property: in case on + The argument "kind" determines which action is performed on each property value: + The action (remove or set) is performed on each property value of each property: in case of lists, it is performed on each list element. The action is only performed if the condition that is provided is fulfilled, i.e. the callable ``condition`` returns True. The callable ``condition`` must take the property value (or list element) as the sole argument. Thus, with "remove" you can conditionally remove values and with "set" you can conditionally - replace values + replace values. + + Args: + node (SyncNode): The node which provides the properties (and their values) to operate on. + condition (Callable): A function with one argument which is interpreted as a condition: Only if + it returns True for the property value, the action is executed. + kind (str): Either "remove" or "set" depending on whether you want to remove the property or replace the property. + value (Callable): A function returning a new value that is set as the property value. This function receives the old value as the single argument. """ for p in node.properties: if isinstance(p.value, list): -- GitLab