SEPDecorators

SEPModules.SEPDecorators.WRAPPER_PREFIX: Final[str] = 'wrapped'

The name to use for wrapped functions.

Decorator Utils

SEPModules.SEPDecorators.copy_func_attrs(func, func_from, wrapper_name)

Copies the __name__, __doc__, and if possible __annotations__ attributes of func_from to func. The name will follow the following form: WRAPPER_PREFIX _ wrapper_name _ func_from's name.

Parameters
  • func (Callable[[...], SEPModules.SEPDecorators._R]) – the function whose attributes are to be updated

  • func_from (Callable) – the function whose attributes should be copied to func

  • wrapper_name (AnyStr) – together with WRAPPER_PREFIX this will be prefixed to the output function’s name

Returns

the function with copied attributes

Return type

Callable[[…], SEPModules.SEPDecorators._R]

SEPModules.SEPDecorators.lock(func, error)

Lock a function by unconditionally raising the passed error upon it being called.

Parameters
  • func (Callable) – the function to copy attributes from to populate the new locked method

  • error (Union[Exception, Callable[[...], Exception]]) – can be one of two types: * an exception object * a callable which received the arguments that were passed to func which returns an exception

Returns

a new function which always raises the exception defined by error upon being called

Return type

Callable[[…], NoReturn]

Decorators

@SEPModules.SEPDecorators.timed

Times the decorated function and prints the amount of time it took to execute.

Returns

the return value of provided function

@SEPModules.SEPDecorators.timed_return

Same functionality as timed() decorator but does not print automatically. Can be used in the following way:

@timed_return
def advanced_add(a: int, b: int) -> int:
        for _ in range(b):
                a += 1
        return a

And now calling the function:

result, time = advanced_add(20, 621421)
Returns

the return value of the function and the time it took to execute in seconds