[Python-ideas] Support other dict types for type.__dict__
victor.stinner at haypocalc.com
Sat Feb 25 03:19:19 CET 2012
>> Can't this also be done using metaclasses?
Yes, my current proof-of-concept (PoC) uses a metadata with __prepare__.
> The class body can be executed "in" any mapping. Then I’m not sure but it
> looks like type.__new__ only takes a real dict. You have to do something in
> your overridden __new__ to eg. keep the OrderedDict’s order.
type.__new__ accepts any class inheriting from dict. My frozendict PoC
inherits from dict, so it just works. But the point is that
type.__new__ makes a copy of the dict and later it is no more possible
to replace the dict.
I would like to be able to choose the type of the __dict__ of my class.
More information about the Python-ideas