[Python-Dev] Reasons behind misleading TypeError message when passing the wrong number of arguments to a method

Michael Foord fuzzyman at voidspace.org.uk
Thu May 20 01:47:33 CEST 2010


On 20/05/2010 00:42, Giampaolo Rodolà wrote:
>>>> class A:
>>>>          
> ...     def echo(self, x):
> ...             return x
> ...
>    
>>>> a = A()
>>>> a.echo()
>>>>          
> Traceback (most recent call last):
>    File "<stdin>", line 1, in<module>
> TypeError: echo() takes exactly 2 arguments (1 given)
>    
>>>>          
> I bet my last 2 cents this has already been raised in past but I want
> to give it a try and revamp the subject anyway.
> Is there a reason why the error shouldn't be adjusted to state that
> *1* argument is actually required instead of 2?
>
>    

+1 - I've seen many newbies confused by this error and I sometimes do a 
double-take myself.

All the best,

Michael

> --- Giampaolo
> http://code.google.com/p/pyftpdlib
> http://code.google.com/p/psutil
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.




More information about the Python-Dev mailing list