Various coding utils (e.g. around function decoration)


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

Returns unique objects in a possibly nested (one level) list of objects.

Preserves the original order in which unique objects first occurred.

For example: >>> flatten_unique([1, [2, 20, 6], 10, [6, 2]]) <<< [1, 2, 20, 6, 10]

flexmeasures.utils.coding_utils.get_classes_module(module, superclass, skiptest=True) dict

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():


@register_something def default_name():


Thanks to https://stackoverflow.com/questions/3888158/making-decorators-with-optional-arguments#comment65959042_24617244

flexmeasures.utils.coding_utils.sort_dict(unsorted_dict: dict) dict

Decorator for printing the time it took to execute the decorated function.