[Python-ideas] Explicit self argument, implicit super argument

Luke Stebbing luke.stebbing at gmail.com
Mon Nov 19 21:20:28 CET 2007


On 11/19/07, Guido van Rossum <guido at python.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.

Luke



More information about the Python-ideas mailing list