[Python-3000] Metaclasses in Python 3000: Draft 2
Jack Diederich
jackdied at jackdied.com
Wed Mar 14 18:13:43 CET 2007
On Wed, Mar 14, 2007 at 12:29:09AM -0700, Talin wrote:
> # The metaclass
> class OrderedClass(type):
>
> # The custom dictionary
> class member_table(dict):
<snip>
I would move the member_table class out of the OrderedClass namespace so
no one gets any funny ideas that it has to be nested.
> Alternate Proposals
>
> Another good suggestion was to simply use an ordered dict for all
> classes, and skip the whole 'custom dict' mechanism. This was based
> on the observation that most use cases for a custom dict were for
> the purposes of preserving order information. However, this idea has
> two drawbacks, first because it means that an ordered dict
> implementation would have to be added to the set of built-in types
> in Python, and second because it would impose a slight speed (and
> complexity) penalty on all class declarations.
FYI, I did a hacky implementation to test speed by making a copy of
dictobject.c and storing key names in a PyList on the object. The slowdown
for inserting 100k unique keys (/usr/share/dict/words) was 10%. There
was no appreciable slowdown for lookup (it uses the normal hash lookup).
I didn't implement deletion so I don't know how much it would suffer.
-Jack
More information about the Python-3000
mailing list