[Python-Dev] Classes and Metaclasses in Smalltalk

Thomas Heller thomas.heller@ion-tof.com
Wed, 2 May 2001 15:12:40 +0200


[Greg Ward]

> On 02 May 2001, Guido van Rossum said:
> > Yes, I can see how to write super() using current tools (or 1.5.2
> > even).  The problem is that this makes super calls even more wordy
> > than they already are!  I can't think of anything that wouldn't
> > require compiler support though.
> 
> I was just doing some gedanken with various ways to spell "super", and I
> think my favourite is the same as Java's (as I remember it):
> 
> class MyClass (BaseClass):
>     def foo (self, arg1, arg2):
>          super.foo(arg1, arg2)
> 
> 
> Since I don't know much about Python's guts, I can't say how
> implementable this is, but I like the spelling.  The semantics would be
> something like this (with adjustments to the reality of Python's guts):
> 
>   * 'super' is a magic object that only makes sense inside a 'def'
>     inside a 'class' (at least for now; perhaps it could be generalized
>     to work at class scope as well as method scope, but let's keep
>     it simple)
> 
>   * super's notional __getattr__() does something like this:
>     - peek at the calling stack frame and fetch the calling function
>       (MyClass.foo) and the first argument to that function (self)
>     - [is this possible?] ensure that calling_function is a bound
>       method, and that it's bound to the self object we just plucked
>       from the stack; raise a "misuse of super object" exception if not
>     - walk the superclass tree starting at self.__class__.__bases__
Caareful!
The search in the above context must start at MyClass.__bases__
which may not be the same as self.__class__.__bases__.

Thomas