noob question: "TypeError" wrong number of args

Edward Elliott nobody at 127.0.0.1
Mon May 1 23:46:05 CEST 2006


Holger wrote:
> oops, that was kinda embarrassing.

It's really not.  You got a completely unhelpful error message saying you
passed 2 args when you only passed one explicitly.  The fact the b is also
an argument to b.addfile(f) is totally nonobvious until you know that 1) b
is an object not a module*, and 2) objects pass references to themselves as
the first argument to their methods.  The syntax "b." is completely
different from the syntax of any other type of parameter.

The mismatch between the number of parameters declared in the method
signature and the number of arguments actually passed is nonobvious,
unintuitive, and would trip up anybody who didn't already know what was
going on.  It's ugly and confusing.  It's definitely a wart on the
langauge.

Making people pass 'self' explicitly is stupid because it always has to be
the first argument, leading to these kinds of mistakes.  The compiler
should handle it for you - and no, explicit is not *always* better than
implicit, just often and perhaps usually.  While it's easy to recognize
once you know what's going on, that doesn't make it any less of a wart.

* technically modules may be objects also, but in practice you don't declare
self as a parameter to module functions



More information about the Python-list mailing list