[Python-ideas] Explicit self argument, implicit super argument
arno at marooned.org.uk
Mon Nov 19 22:54:50 CET 2007
On 19 Nov 2007, at 20:42, Neil Toronto wrote:
> Now, correct me if I'm wrong, but it seems there are only two use
> for DistantParentOfD.method(D_instance, ...):
> 1. The Good Case: you know the "next-method" as determined by the MRO
> isn't the right one to call. Multiple inheritance can twist you into
> this sort of behavior, though if it does, your design likely needs
> 2. The Evil Case: you know the override method as defined by D isn't
> one you want for your extra-special D instance. This should be
> but never encouraged.
> Because the runtime enforces isinstance(D_instance, D), everything
> can be handled with D_instance.method(...) or self.method() or
> super.method(). We know that #1 and #2 above are the uncommon cases,
> which is why the new "super", which covers the common ones, doesn't
> cover those.
> Is it right to say that the explicit "self" parameter only exists to
> enable those two uncommon cases?
Self being explicit makes it less selfish :)
To illustrate, I like that you can do:
return "I am %s and I was made by %s" % (me, self)
>>> print bar.madeby()
I am bar and I was made by foo
This depends on 'self' being explicit and is not related to super.
I didn't know about implicit super, it's probably great but my initial
reaction is that I don't like it :(
def bar(super, self, x, y):
More information about the Python-ideas