[Types-sig] MetaClasses (Non-ASCII art)

Just van Rossum just@letterror.com
Thu, 3 Dec 1998 02:52:58 +0100


>David Ascher wrote:
>> Both of you (MAL and JvR) present schemes in which the notion of class and
>> instance (and something else, call it metaclass) are reified.  This is in
>> contrast, I believe, to GvR's view, which allows unlimited 'levels of
>> metaness', aka turtledepth.

M.-A. Lemburg wrote:
>Can't speak for Just, but in the scheme I have in mind there
>can be any number of objects between Object and the top level
>objects.
>
>I just left them out to avoid confusion (see my note at the bottom
>of the drawing).

Same here: I showed a possible hierarchy that would (if it could!)
implement a system which is semantically very close to what we have now.
What I'm really saying is:

	an object's implementation lives in it's class
	how the two interact is defined by it's class's class

To use the current Python object model as an example as how this could work:

	an instance's implementation lives in it's __class__
	how one accesses attributes of object is defined by
	object.__class__.__class__ (ie. search ob.__dict__, then ask class)

	class = object.__class__

	class's implementation lives in it's __class__
	how one accesses attributes from class is defined by
	class.__class__.__class__ (ie. search class.__dict__, then
	ask each of class.__bases__)

(to turn this into Marc-André's scheme:
     print string.replace(justs_scheme, "__class__.__class__", "__meta__")
;-)

Or, in other words:

	the instance protocol is implemented by:
		instance.__class__.__class__
	the class protocol is implemented by
		instance.__class__.__class__.__class__


What I hope to find out is what I'm saying is 1) possible, 2) makes sense...

So, to reimplement Python's notion of instances and classes using "my" meta
protocol you only _need_ 4 levels, but noone will stop you to invent a few
more...

Just