[Python-Dev] Preserving the definition order of class namespaces.

Nick Coghlan ncoghlan at gmail.com
Sun May 24 04:04:21 CEST 2015


On 24 May 2015 at 11:15, Eric Snow <ericsnowcurrently at gmail.com> wrote:
> tl;dr Are there any objections to making making the default
> cls.__prepare__ return OrderedDict instead of dict (and preserve that
> order in a list on the class)?
>
> A couple years ago [1][2] I proposed making class definition
> namespaces use OrderedDict by default.  Said Guido [3]:
>
>     I'm fine with doing this by default for a class namespace; the type of
>     cls.__dict__ is already a non-dict (it's a proxy) and it's unlikely to
>     have 100,000 entries.
>
> It turns out making cls.__dict__ an OrderedDict isn't reasonably
> tractable (due to the concrete API v. subclasses), but really that
> isn't what I was looking for anyway.
>
> Regardless, since it's been a while I just want to run the proposal by
> the group again.  I'm hopeful about landing my C implementation of
> OrderedDict [4] in the next few days.  Also, I have a patch up [5]
> that implements using OrderedDict for class definitions.  So mostly I
> just want to double check that I'm still good to go.

While it isn't controversial (since you already have the +1 from
Guido), it's worth writing up the change as a PEP for 3.6 anyway,
since that then provides clearer guidance to alternate implementations
that they're going to need to change the way their class namespace
evaluation works for 3.6.

Let's not repeat the zip archive and directory execution mistake that
3.5's PEP 441 aimed to resolve :)

PEP 487 could then be updated to reference that PEP as part of the
rationale for dropping the "easy namespace customisation" aspect of
the proposal.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list