I'm trying to make sure running help()
at the Python 2.7 REPL displays the __doc__
for a function that was wrapped with functools.partial
. Currently running help()
on a functools.partial
'function' displays the __doc__
of the functools.partial
class, not my wrapped function's __doc__
. Is there a way to achieve this?
Consider the following callables:
def foo(a):"""My function"""passpartial_foo = functools.partial(foo, 2)
Running help(foo)
will result in showing foo.__doc__
. However, running help(partial_foo)
results in the __doc__
of a Partial object.
My first approach was to use functools.update_wrapper which correctly replaces the partial object's __doc__
with foo.__doc__
. However, this doesn't fix the 'problem' because of how pydoc.
I've investigated the pydoc code, and the issue seems to be that partial_foo
is actually a Partial object not a typical function/callable, see this question for more information on that detail.
By default, pydoc will display the __doc__
of the object type, not instance if the object it was passed is determined to be a class by inspect.isclass. See the render_doc function for more information about the code itself.
So, in my scenario above pydoc is displaying the help of the type, functools.partial
NOT the __doc__
of my functools.partial
instance.
Is there anyway to make alter my call to help()
or functools.partial
instance that's passed to help()
so that it will display the __doc__
of the instance, not type?