Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a pretty hacky way to do this. I wrote the following function to override the <code>__builtins__.help</code> function:</p> <pre><code>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) </code></pre> <p>Then just replace it in the REPL with:</p> <pre><code>__builtins__.help = partialhelper </code></pre> <p>This works and doesn't seem to have any major downsides, yet. However, there isn't a way with the above naive implementation to support still showing the <code>__doc__</code> of <em>some</em> <code>functools.partial</code> objects. It's all or nothing, but could probably attach an attribute to the wrapped (original) function to indicate whether or not the original <code>__doc__</code> should be shown. However, in my scenario I never want to do this.</p> <p>Note the above does NOT work when using IPython and the <a href="http://ipython.org/ipython-doc/dev/interactive/reference.html#embedding-ipython" rel="nofollow">embed functionality</a>. This is because IPython directly sets the shell's namespace with references to the 'real' <code>__builtin__</code>, see the <a href="https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py#L1121" rel="nofollow">code</a> and old <a href="http://mail.python.org/pipermail/python-dev/2001-April/014068.html" rel="nofollow">mailing list</a> for information on why this is.</p> <p>So, after some investigation there's another way to hack this into IPython. We must override the <code>site._Helper</code> class, which is used by IPython to <a href="https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py#L1136" rel="nofollow">explicitly setup the help system</a>. The following code will do just that when called BEFORE <code>IPython.embed</code>:</p> <pre><code>import site site._Helper.__call__ = lambda self, *args, **kwargs: partialhelper(*args, **kwargs) </code></pre> <p>Are there any other downsides I'm missing here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload