flexmeasures.utils.coding_utils
Various coding utils (e.g. around function decoration)
Functions
- flexmeasures.utils.coding_utils.delete_key_recursive(value, key)
Delete key in a multilevel dictionary
- flexmeasures.utils.coding_utils.deprecated(alternative, version: str | None = None)
Decorator for printing a warning error. alternative: importable object to use as an alternative to the function/method decorated version: version in which the function will be sunset
- flexmeasures.utils.coding_utils.find_classes_module(module, superclass)
- flexmeasures.utils.coding_utils.find_classes_modules(module, superclass, skiptest=True)
- flexmeasures.utils.coding_utils.flatten_unique(nested_list_of_objects: list) list
Get unique sensor IDs from a list of sensors_to_show.
Handles: - Lists of sensor IDs - Dictionaries with a sensors key - Nested lists (one level)
- Example:
Input: [1, [2, 20, 6], 10, [6, 2], {“title”:None,”sensors”: [10, 15]}, 15]
Output: [1, 2, 20, 6, 10, 15]
- flexmeasures.utils.coding_utils.optional_arg_decorator(fn)
A decorator which _optionally_ accepts arguments.
So a decorator like this:
@optional_arg_decorator def register_something(fn, optional_arg = ‘Default Value’):
… return fn
will work in both of these usage scenarios:
@register_something(‘Custom Name’) def custom_name():
pass
@register_something def default_name():
pass
- flexmeasures.utils.coding_utils.timeit(func)
Decorator for printing the time it took to execute the decorated function.