Q? Calling nearest inherited method
Guido van Rossum
guido at python.org
Thu May 18 11:09:25 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...
> 1) The lowest problem: you have to define it for each function in each
> class in the hierarchy to have a clean model.
Yes, but this adds to the documentation of the class.
> 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...
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list