[Python-3000] PEP for Metaclasses in Python 3000

Phillip J. Eby pje at telecommunity.com
Sat Mar 10 21:22:30 CET 2007


At 08:45 PM 3/10/2007 +1300, Greg Ewing wrote:
>Jack Diederich wrote:
>
> > I am a very big fan of ordered dicts in classes.  One possibility is that
> > suites in classes always store their order in a special dict that keeps a
> > side list of key order.  A final invisible class decorator around
> > every class would then toss out the order and leave only a regular dict.
>
>Is it really necessary to toss out the order at all?
>I'm skeptical that class dictionaries are either created
>or modified anywhere near often enough for there to
>be any noticeable performance penalty here.
>
>In any case, I've thought of a way to reduce the performance
>penalty to near-zero. Consider that the compiler knows
>all the names that will be assigned in the class dict
>and what order they are in. So all it needs to do is
>compile...

This wouldn't help any of the other use cases for custom metaclass 
dictionaries.  I.e., the ability to use a custom dictionary type is a 
feature, not a bug.  (Note that using a custom dictionary means you can 
override its __getitem__ as well as its __setitem__, thereby influencing 
the execution of the class body, defining special names, etc.)



More information about the Python-3000 mailing list