Skip to content
Snippets Groups Projects
Commit ab3f1431 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

DOC: improved docstring of the _for_each helper function

parent 3b50909a
Branches
Tags
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!167Sync Graph
...@@ -44,16 +44,24 @@ logger = logging.getLogger(__name__) ...@@ -44,16 +44,24 @@ logger = logging.getLogger(__name__)
def _for_each_scalar_value(node: SyncNode, condition: Callable[[Any], bool], kind: str, 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 """ 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 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 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. ``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 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: for p in node.properties:
if isinstance(p.value, list): if isinstance(p.value, list):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment