[Python-Dev] Classes and Metaclasses in Smalltalk

M.-A. Lemburg mal@lemburg.com
Wed, 02 May 2001 16:29:20 +0200


Guido van Rossum wrote:
> 
> > Here's an implementation of what I currently use to track down
> > the basemethod (taken from mx.Tools):
> 
> How am I supposed to use this?
> 
> I tried this:
> 
>     class B:
>         def foo(self):
>             print "B.foo"
> 
>     class C(B):
>         def foo(self):
>             print "C.foo"
>             B.foo(self)
>             print basemethod(self.foo) # Expect this to be B.foo

This finds the basemethod of self.foo meaning the method overridden
by D.foo. To get at the basemethod of C.foo, you'd have to call

basemethod(self, C.foo)

Note that the intent here is to be able to call basemethods
even in case the defining class is only mixin class -- a very
common situation at least in many of my applications (keeps
inheritance trees shallow and increases readability of the code).
 
>     class D(C):
>         def foo(self):
>             print "D.foo"
>             C.foo(self)
> 
>     d = D()
>     d.foo()
> 
> but the call to basemethod(self.foo) in C prints C.foo, not B.foo as
> required.
> 
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> 
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://mail.python.org/mailman/listinfo/python-dev

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/