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 offunc_fromtofunc. 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
funcwrapper_name (AnyStr) – together with
WRAPPER_PREFIXthis 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
funcwhich returns an exception
- Returns
a new function which always raises the exception defined by
errorupon 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