(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
   ">

(original) (raw)


(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