A simple collection of python decorators and utils.
A decorator to automatically parse arguments of supported types from strings to datetime-like objects.
@autoparse_dates('start')
def some_other_function(start: pd.Timestamp, n_threads: int = 3, end: datetime = '2021-01-05'):
...
Decorator to return a default value in case of an (un)specific exception occurs in the decorated function.
@return_on_failure('failed', RuntimeError)
def this_function_fails():
...
Decorator that compares the serialized/unserialized objects being passed as parameters to ensure their value did not change, emulating the const keyword of other languages.
@constants
def this_function_does_not_modify_its_arguments(first_arg: list, second_arg: List[str] = ['1']):
...
Decorator that adds a formatted log line before/after running a function.
Some special variables are available: func_name
and results
.
It's also possible to add your own variables.
@log_wrapper(pre_format='beginning', post_format='end, result: {result}')
def this_function_returns_something():
...