Skip to content

MarcDuQuesne/baffi

Repository files navigation

Baffi

A simple collection of python decorators and utils.

Python 3.9 Python 3.10 Coverage Status Open Issues Tests

Overview

autoparse_dates

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'):
        ...

return_on_failure

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

constants

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']):
    ...

log_wrapper

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

About

A collection of python decorators and utils.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages