[Python-Dev] [Python-3000] Removing 'self' from method definitions (original) (raw)

Jim Jewett jimjjewett at gmail.com
Thu Apr 13 20:54:11 CEST 2006


(Cc to python dev, as my question is really about 2.x)

On 4/13/06, Ian Bicking <ianb at colorstudy.com> wrote:

... the self in the signature (and the miscount of arguments in TypeError exceptions) ...

Even in the 2.x line, the TypeError messages should be improved.

>>> # No syntax errors when creating m()
>>> class C:
    def m(): pass

but the method can't actually be called, and won't quite say why.

>>> # This message is good
>>> C.m()

Traceback (most recent call last):
  File "<pyshell#101>", line 1, in -toplevel-
    C.m()
TypeError: unbound method m() must be called with C instance as

first argument (got nothing instead)

but the obvious fix of using an instance is just confusing

>>> C().m()

Traceback (most recent call last):
  File "<pyshell#102>", line 1, in -toplevel-
    C().m()
TypeError: m() takes no arguments (1 given)

Could it at least say something like "(1 given, including self)"? I suppose the argument might be named something other than self, particularly in C code, but ... that strikes me as a smaller problem than the mysteriously appearing invisible argument.

-jJ



More information about the Python-Dev mailing list