[Python-Dev] Quick poll: should help() show bound arguments?

Zachary Ware zachary.ware+pydev at gmail.com
Sat Jan 25 05:18:19 CET 2014


On Fri, Jan 24, 2014 at 10:07 PM, Larry Hastings <larry at hastings.org> wrote:
>
> (Quick, because apparently nobody reads the long ones!)
>
> In Python 3.3:
>
>>>> class C:
> ...    def foo(self, a):  pass
> ...
>>>> c = C()
>>>> help(c.foo)
>
> shows you the signature "foo(self, a)".  As in, it claims it accepts two
> parameters.  The function actually only accepts one parameter, because
> "self" has already been bound.  inspect.signature gets this right:
>
>>>> import inspect
>>>> str(inspect.signature(c.foo))
> '(a)'
>
> but inspect.getfullargspec does not:
>
>>>> inspect.getfullargspec(c.foo)
> FullArgSpec(args=['self', 'a'], varargs=None, varkw=None, defaults=None,
> kwonlyargs=[], kwonlydefaults=None, annotations={})
>
>
> help() gets its text from pydoc.  pydoc uses inspect.getfullargspec to
> produce the signature.
>
> When I added support for introspection on builtins, I wanted help() to show
> their signature too.  But inspect.getfullargspec doesn't support
> introspection on builtins.  So I had to use inspect.signature.  Which means
> the behavior is inconsistent: help() on a method of an instance of a builtin
> class *doesn't* show "self".
>
>
> FYI, the relevant issues:
>
> help(instance_of_builtin_class.method) does not display self
>
> http://bugs.python.org/issue20379
>
> inspect.getfullargspec should use __siganture__
>
> http://bugs.python.org/issue17481
>
>
> What should it be?
>
> A) pydoc and help() should not show bound parameters in the signature, like
> inspect.signature.
> B) pydoc and help() should show bound parameters in the signature, like
> inspect.getfullargspec.
>
> I'll tally the results if there's interest.  I'd assume a "vote for A" = +1
> on A and -1 on B.  You can express your vote numerically if you like.  I'm
> voting for A.
>

I vote A: it makes sense (though B does too, to an extent), and the
patch to make help() consistent for Python and C implemented methods
is simply removing two lines from pydoc.  I'm not sure how convoluted
it might become to make it work the other way.

-- 
Zach


More information about the Python-Dev mailing list