Order in metaclass

Nicolas Fleury nid_oizo at yahoo.com_remove_the_
Wed Oct 13 12:41:03 EDT 2004


Carlos Ribeiro wrote:
> I don't think you're crazy. OTOH, defining 'ordering' is difficult. Is
> it the alphabethical ordering, or is it the ordering of insertion?

Insertion.  The point is that *there is* an order in the code.

> Either way is arbitrary and it not going to satisfy everyone.

The ordereddict object could provide a method to change the order of 
keys.  Right now, in configuration dictionaries I must do (simplified):

SomeConfig(['y', 'x'], {'y': 1, 'x': 2})
or
SomeConfig(MyOrderedDict([('y', 1), ('x', 2)]))

what I would like is to do:
SomeConfig(o{'y': 1, 'x': 2})

> I am beginning to get a glimpse of the theorethical implications of
> Python's metaclass design and implementation. It's an amazingly clever
> solution (the __metaclass__ magic name, I mean); but I suspect that it
> could be more powerful if there were a way to detect the metaclass
> *before* the class statement is first processed; in this way, the
> metaclass could provide a custom locals() dict, or implement other
> types of hook for the class being created. But this is really hard
> stuff, with implications beyond my current understanding, and I don't
> feel prepared to argue at python-dev about it, really.

I feel the same way.  I was thinking about writing a PEP for an 
ordereddict, suggesting in it that one of the applications could be the 
metaclasses.  An ordereddict could also contain a dict, and could be 
used only temporarily only during metaclass creation and after just keep 
the normal dictionary in it.

Regards,
Nicolas



More information about the Python-list mailing list