metaclasses (was Re: Hooks, aspect-oriented programming, and design by contract)

James_Althoff at i2.com James_Althoff at i2.com
Mon Jan 28 20:00:30 EST 2002


[Pedro Rodriguez ]
>So a class definition in ST, do :
>    M -> C, M'
>where :
>    M is usually a predefined Metaclass
>    M' a new metaclass which is a subclass of M (?)
>                    or which has M as a metaclass (?)
>    C the new class whose metaclass is M' (?)
>                 or its metaclass is M, and M' is just a place holder (?)

The above pretty much captures the spirit of things.

The details are more like:

You tell class Class to create a new subclass of class Spam named 'Eggs'.
Class Class gets Spam's metaclass, Spam.__metaclass__, and makes a subclass
of it: Eggs.__metaclass__.  This newly created metaclass, Eggs.
__metaclass__, is an *instance* of class Metaclass.  Class Class then tells
Eggs.__metaclass__ to make an instance of itself which results in a new
class, Eggs.  Class Class makes the newly created Eggs class object a
subclass of the Spam class object and returns it to you.  In the end you
have class Eggs and metaclass Eggs.__metaclass__ where Eggs is a subclass
of Spam and where Eggs.__metaclass__ is a subclass of Spam.__metaclass__.

Jim





More information about the Python-list mailing list