19 Nov 2007 19 Nov '07
On 11/19/07, Guido van Rossum firstname.lastname@example.org wrote:
The reason for explicit self in method definition signatures is semantic consistency. If you write
class C: def foo(self, x, y): ...
This really *is* the same as writing
class C: pass
def foo(self, x, y): ... C.foo = foo
What about an instancemethod decorator?
@instancemethod(C) def foo(x, y): ...
And of course it works the other way as well: you really *can* invoke foo with an explicit argument for self as follows:
class D(C): ...
C.foo(D(), 1, 2)
Couldn't __builtin__.__super__ be used? It would look pretty weird if you invoked a method higher up the MRO, though.
I find that these cases come up rarely in my code, while I forget the 'self' argument much more frequently, but YMMV.