1-Minute Metaclass

http://ianbicking.org/docs/pycon2005

Ian Bicking
Imaginary Landscape Web Development
imagescape.com

It

class OneMinuteMetaclass(type):
    def __new__(meta, class_name, bases, new_attrs):
        cls = type.__new__(
            meta, class_name, bases, new_attrs)
        if new_attrs.has_key('__classinit__'):
            cls.__classinit__ = staticmethod(
                cls.__classinit__.im_func)
        cls.__classinit__(cls, new_attrs)
        return cls

Usage

class Form(object):
    __metaclass__ = OneMinuteMetaclass
    fields = []
    def __classinit__(cls, new_attrs):
        for name, value in new_attrs.values():
            if isinstance(value, Field):
                value.name = name
                self.fields.append(value)