[Python-Dev] Classes and Metaclasses in Smalltalk

Donald Beaudry Donald Beaudry <donb@abinitio.com>
Wed, 02 May 2001 10:41:14 -0400


Guido van Rossum <guido@digicool.com> wrote,
> [Greg Ward, welcome back!]
> >   * '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)
> 
> Yes, that's about the only way it can be made to work.  The compiler
> will have to (1) detect that 'super' is a free variable, and (2) make
> it a local and initialize it with the proper magic.  Or, to relieve
> the burden from the symbol table, we could make super a keyword, at
> the cost of breaking existing code.

I'm not at all sure I like the idea of 'super'.  It's far more magic
that I am used to (coming from Python at least).  Currently, we spell
'super' like this:

     class foo(bar):
         def __repr__(self):
             return bar.__repr__(self)  # that's super!

I like the explicit nature of it.  As Guido points out however, this
ends up being ambiguous when we try to make classes more
"instance-like".

Now, how do I like to spell super?

     class foo(bar):
         def __repr__(self):
             return bar._.__repr__(self)  # now that's really super!

or, for those who like the "keyword":

     class foo(bar):
         def __repr__(self):
             super = bar._
             return super.__repr__(self)

The trick here in the implementation of getattr on the '_'.  It return
a proxy object for the class.  When attributes are accessed through it
a different search path is taken.  This path is the same path that
would be taken by instance attribute look up.  In my code, I refer to
this object as the 'unbound instance'.  Since accessing a function
through this object will yield an unbound instance method, the name
makes sense to me.

--
Donald Beaudry                                     Ab Initio Software Corp.
                                                   201 Spring Street
donb@init.com                                      Lexington, MA 02421
                  ...So much code, so little time...