I found a pretty hacky way to do this. I wrote the following function to override the __builtins__.help function:
def partialhelper(object=None): if isinstance(object, functools.partial): return pydoc.help(object.func) else: # Preserve the ability to go into interactive help if user calls # help() with no arguments. if object is None: return pydoc.help() else: return pydoc.help(object)
Then just replace it in REPL with:
__builtins__.help = partialhelper
This works and does not seem to have any major flaws. However, there is no way for the aforementioned naive implementation to support still showing __doc__ some functools.partial objects. This is all or nothing, but it is possible, perhaps, to attach an attribute to a wrapped (original) function to indicate whether the original __doc__ should be shown. However, in my scenario, I never want to do this.
Please note that the above does not work when using IPython and the built-in function . This is because IPython directly defines a shell namespace with links to "real" __builtin__ , see the code and the old mailing list for information on why this is so.
So, after some investigation, there is another way to crack this in IPython. We must override the site._Helper class that IPython uses to explicitly configure the help system . The following code will only do this when calling BEFORE IPython.embed :
import site site._Helper.__call__ = lambda self, *args, **kwargs: partialhelper(*args, **kwargs)
Are there any other disadvantages missing here?
source share