lib5c.util.pretty_decorator module¶
Module providing the @pretty_decorator
meta-decorator.
-
lib5c.util.pretty_decorator.
pretty_decorator
(dec)[source]¶ Decorator to turn any existing decorator into a “pretty” decorator.
A “pretty” decorator retains the signature information of the original function, improving the readability of
help(func)
and auto-generated documentation.This functionality is completely cosmetic.
Requires the optional dependency
decorator
- if importing this fails, the decorator will not be modified.- Parameters
dec (function) – The decorator to prettify.
- Returns
The pretty decorator.
- Return type
function
Examples
>>> from lib5c.util.pretty_decorator import pretty_decorator >>> @pretty_decorator ... def dec1(func): ... def wrapped_func(*args, **kwargs): ... print("you've been decorated") ... return func(*args, **kwargs) ... return wrapped_func >>> @dec1 ... def my_func(a, b): ... "Adds two numbers" ... return a + b >>> my_func(1, 2) you've been decorated 3 >>> help(my_func) Help on function my_func in module lib5c.util.pretty_decorator: my_func(a, b) Adds two numbers