[Python-Dev] Re: More informative error messages

Gregory P. Smith greg at electricrain.com
Wed Oct 8 04:03:02 EDT 2003


On Tue, Oct 07, 2003 at 10:56:34AM +0200, Alex Martelli wrote:
> >
> >   TypeError: foo() takes exactly 1 argument (2 given)
> 
> A perennial beginners' confusion (recently highlighted in a c.l.py thread
> whose subject claimed that Python can't count;-) is about that "number
> of arguments given" number: one calls zoop.bleep() and is told bleep
> "takes exactly 2 arguments (1 given)" when one is sure that one has
> given no argument at all (and should give exactly 1) -- the implied 'self'
> causing the beginners' confusion.  It seems to me that, if we work on these
> messages, we may be able to distinguish the bound-method case into
> 
> TypeError: bound method bleep() of Zoop instance takes exactly 1
> argument (0 given)

I've had to answer that question about the "wrong" numbers for python
newbies[1] frequently as well.  Even a simple cleaning up of the user
visible off by one error to be:

  TypeError: method bleep() takes exactly 1 argument (0 given)

At the time the TypeError is constructed it shouldn't add serious overhead
to check if its a method or a function and subtract 1 accordingly.

Greg

[1] where newbie is defined as someone who doesn't know the answer to
    that yet ;)



More information about the Python-Dev mailing list