[Python-3000] Metaclasses in Py3K

Talin talin at acm.org
Sun Dec 17 00:41:14 CET 2006

Steven Bethard wrote:
>> The main issue for me is that I think that its important to distinguish
>> between get/set operations that are done at class definition time, and
>> get/set operations that are done later, after the class is created.
> Why?  Can you explain your use case?  Everything I'd care to do would
> treat later get/set operations on the class in the same way.

Imagine a metaclass that's being used to declare a C struct. When the 
class is "finished", we examine the dictionary and compute the layout of 
the struct and it's size in bytes, taking into account padding bytes and 
alignment and such.

Once the struct has been computed, however, you can't go back and add 
new fields, unless you want to add code that automatically re-compute 
the layout of the C struct when this occurs. More likely, attributes 
which were added to the class after class creation would be treated as 
regular Python class variables.

Now, I'm not saying that this is the way a C struct class would have to 
work. I'm trying to craft an example - the idea is that once the 
'finishing' function has been called, there are certain kinds of class 
member definitions that may no longer be available.

(Other than that - your general sketch of how metaclasses ought to work 
makes a lot of sense to me.)

-- Talin

More information about the Python-3000 mailing list