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

Greg Ewing greg.ewing at canterbury.ac.nz
Fri May 21 03:31:33 CEST 2010


Giampaolo RodolĂ  wrote:

"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.

It's hard to see how this could be improved. If you had been intending to call an unbound method, the comment about arguments would have been relevant -- you were supposed to supply one but didn't. Python is unable to read your mind and figure out that you really meant something else altogether.

BTW, unbound methods no longer exist in Py3, so you would get the standard message about incorrect number of arguments instead. Not sure whether that's better or worse in this situation.

-- Greg



More information about the Python-Dev mailing list