Q? Calling nearest inherited method
Guido van Rossum
guido at python.org
Thu May 18 23:36:08 EDT 2000
> Laurent POINTAL wrote:
> > On Wed, 17 May 2000 18:37:00 GMT, Guido van Rossum <guido at python.org>
> > wrote:
> > >: There's a better way. (I believe Jeremy Hylton first suggested this; he saw
> > >: it as an idiom in another language:)
> > >:
> > >: class C(B):
> > >: super_doit = B.doit
> > >: def doit(self, arg):
> > >: self.super_doit(arg)
> > >:
> > >: This avoids the need to explicitly pass self.
> > Not sure its really better...
> > 2) The biggest problem, it can go into infinite recursion...
> [details omitted]
> Argh! Good catch. My suggestion: use a naming convention
> where it's called B_doit instead of super_doit. But this *does*
> make it less elegant, and you now need to know the base class name...
Jeremy just pointed out to me that he has a very elegant solution:
he uses __super_doit = B.doit.
This nicely makes it class-specific without working the class name
into the identifier explicitly. I think this is more elegant than
calling B.doit(self, arg).
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list