[Python-ideas] Explicit self argument, implicit super argument
ntoronto at cs.byu.edu
Mon Nov 19 23:03:56 CET 2007
Arnaud Delobelle wrote:
> Self being explicit makes it less selfish :)
> To illustrate, I like that you can do:
> class Foo(str):
> def mybar(self):
> class Bar(str):
> def madeby(me):
> return "I am %s and I was made by %s" % (me, self)
> return Bar
> >>> foo=Foo("foo")
> >>> #bar=foo.mybar() # typo
> >>> Bar=foo.mybar()
> >>> bar=Bar("bar")
> >>> print bar.madeby()
> I am bar and I was made by foo
Ah, I see. If self were passed implicitly, you would need to make a
Bar.__init__ that received and stored the outer self. I think I'd call
this a third uncommon case. Outside functional idioms, common is usually
> 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 :(
> Why not:
> class Foo:
> def bar(super, self, x, y):
> super.bar(x, y)
Probably because it's way too common to require a decorator for it.
Users would have to make "always use @with_super" into a coding habit.
(Sort of like "self" actually.) It'd also be yet another thing to keep
in mind while reading code: did this method use @with_super or not?
More information about the Python-ideas