[Python-Dev] inspect.getargspec()

Guido van Rossum guido@python.org
Thu, 07 Nov 2002 10:19:58 -0500


> Unfortunately, Python is inconsistent about this.  On the one hand,
> 
> >>> x = []
> >>> push = x.append
> >>> push()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: append() takes exactly one argument (0 given)
> >>>
> 
> On the other,
> 
> >>> class X(list):
> ...     def append(self, item):
> ...         pass
> ...
> >>> push = X().append
> >>> push()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: append() takes exactly 2 arguments (1 given)
> >>>
> 
> I care about matching the error msgs because error msgs are a prime
> trigger for looking up help.  OTOH, when the error msgs are
> inconsistent, you can't win.  I'd count self, myself, as you can
> only suck the signature out of Python-defined callables, and those
> seem consistent about reporting the "real" number of arguments
> required.

I'm with Ping -- the signature returned should only report arguments
you need to supply.  So in the above, the signature for X.append would
be (self, item) but the signature for X().append would be (item).

--Guido van Rossum (home page: http://www.python.org/~guido/)