A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-May/100208.html below:

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

[Python-Dev] Reasons behind misleading TypeError message when passing the wrong number of arguments to a method [Python-Dev] Reasons behind misleading TypeError message when passing the wrong number of arguments to a methodGiampaolo RodolĂ  g.rodola at gmail.com
Thu May 20 11:49:02 CEST 2010
2010/5/20 John Arbash Meinel <john.arbash.meinel at gmail.com>:
> 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?
>>
>
> Because you wouldn't want to have
>
> A.echo()
>
> Say that it takes 1 argument and (-1 given) ?
>
> John
> =:->
>
>

I see that as a different error type: what you're doing there is
calling a method of a class which you haven't instantiated in the
first place.
Actually the error message returned in this other case is not very
clear as well:

"unbound method echo() must be called with A instance as first
argument (got nothing instead)"

It talks about "arguments" while no arguments are actually involved in
the problem: just a class I forgot to initialize.


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4