[Python-Dev] inspect.getargspec()

Patrick K. O'Brien pobrien@orbtech.com
Wed, 6 Nov 2002 21:58:51 -0600


On Wednesday 06 November 2002 08:32 pm, Tim Peters wrote:
> 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.

Except the net (args required minus args given) is the same in both cases. 
Which would argue for not including self in the results of getargspec(). 
Plus, you'll get an error if you try to explicitly pass the first argument. 
So while technically self *is* part of the argspec, I think in practice 
most applications will end up wanting to eliminate it because Python takes 
care of it implicitly. If that turns out to be 90% of the use cases, we 
save everyone a lot of trouble by taking the practical approach and not 
including self in the results returned by getargspec().

-- 
Patrick K. O'Brien
Orbtech      http://www.orbtech.com/web/pobrien
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------