[Python-Dev] Quick poll: should help() show bound arguments?
Larry Hastings
larry at hastings.org
Sat Jan 25 05:07:43 CET 2014
(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.
And yes, that was short for me,
//arry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140124/e6eab326/attachment.html>
More information about the Python-Dev
mailing list