[Python-Dev] PEP 520: Ordered Class Definition Namespace

Eric Snow ericsnowcurrently at gmail.com
Wed Jun 8 10:26:29 EDT 2016


On Wed, Jun 8, 2016 at 1:07 AM, Victor Stinner <victor.stinner at gmail.com> wrote:
>> Abstract
>> ========
>>
>> This PEP changes the default class definition namespace to ``OrderedDict``.
>> Furthermore, the order in which the attributes are defined in each class
>> body will now be preserved in ``type.__definition_order__``.  This allows
>> introspection of the original definition order, e.g. by class decorators.
>>
>> Note: just to be clear, this PEP is *not* about changing ``__dict__`` for
>> classes to ``OrderedDict``.
>
> What is the cost in term of performance?

Do you mean the cost of the PEP?  The extra cost is negligible:
creating an OrderedDict + mutation operations on it.  Note that it is
only used during class definition (execution of the class body).

>
> What can be slower: define a new class and/or instanciate a class?

By "instantiate" do you mean the equivalent of "type(...)" or do you
mean creating a new instance of a class?  As noted above, the impact
of using OrderedDict during class definition is negligible.  During
definition the cost of other operations will usually dwarf any extra
overhead from using an OrderedDict.

-eric


More information about the Python-Dev mailing list