help()
internally looks up the function data using the inspect
module. Unless you overwrite the function meta data by default (if that’s even possible) I don’t think you can get rid of the wrapper function’s definition.
What you can do however is fill the wrapper function’s help text with information from the wrapped function. You can either use the inspect
module yourself (especially the getfullargspec
method), or you can just use the pydoc
module (which is what help
internally uses) to generate it for you.
import pydoc
def wrappedHelpText (wrappedFunc):
def decorator (f):
f.__doc__ = 'This method wraps the following method:\n\n' + pydoc.text.document(wrappedFunc)
return f
return decorator
@wrappedHelpText(worker_function)
def wrapper_function(**args):
worker_function(**args)
Calling help
on that will then generate a more useful output including the original signature.
>>> help(wrapper_function)
Help on function wrapper_function in module __main__:
wrapper_function(**args)
This method wraps the following method:
worker_function(arg1, arg2, arg3)
desired help message:
arg1 - blah
arg2 - foo
arg3 - bar