[Python-3000] PEP for Metaclasses in Python 3000
jcarlson at uci.edu
Sat Mar 10 09:55:00 CET 2007
Greg Ewing <greg.ewing at canterbury.ac.nz> 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.
I agree. Very few classes have significantly more than a few hundred
assignments or accesses during class body execution. I don't think
speed is going to matter enough for us to care.
> The tuple can be a constant of the code object, so the
> only overhead is one extra item added to the dict at
> class creation time, and none at all for subsequent
> access to the class dict. And you don't even need a
> special kind of dict.
a = 1
b = 2
b = 1
a = 2
c = 3
Which is first, a or b? What if ... is runtime-dependent?
Also, depending on the use, one may want to know the order in a 'move to
end' fashion (if a is assigned to multiple times, it ends up in the
ordering as if only the last assignment was done).
More information about the Python-3000