[Python-3000] Metaclasses in Py3K

Talin talin at acm.org
Mon Dec 18 08:46:18 CET 2006


Greg Ewing wrote:
> The main use case for all this seems to be that
> some metaclasses would like to know the order in
> which attributes were defined. So here's an
> alternative proposal: Leave the syntax the way it
> is, and *always* use a specialised dict that
> remembers the order of definition. The metaclass
> can then use that information or ignore it as it
> wishes.

I'm not sure that this is the *only* use case for overriding the 
locals() dict at class definition time, but at the moment I can't think 
of any others. So I won't try to struggle too hard against this idea.

Do you have a specific proposal as to how the information about the 
ordering of definitions could be extracted? I'm assuming that there 
would be an extra attribute that would return a list of keys in the 
order that they were defined. One tricky part here is if the same key 
were to be defined twice (i.e. being overwritten the second time), we 
probably would only want it to appear once, probably at the location 
where it was defined last.

-- Talin


More information about the Python-3000 mailing list