[Python-Dev] Python 3.6 dict becomes compact and gets a private version; and keywords become ordered

Guido van Rossum guido at python.org
Fri Sep 9 13:17:06 EDT 2016

I've been asked about this. Here's my opinion on the letter of the law in 3.6:

- keyword args are ordered
- the namespace passed to a metaclass is ordered by definition order
- ditto for the class __dict__

A compliant implementation may ensure the above three requirements
either by making all dicts ordered, or by providing a custom dict
subclass (e.g. OrderedDict) in those three cases.

I'd like to handwave on the ordering of all other dicts. Yes, in
CPython 3.6 and in PyPy they are all ordered, but it's an
implementation detail. I don't want to *force* all other
implementations to follow suit. I also don't want too many people
start depending on this, since their code will break in 3.5. (Code
that needs to depend on the ordering of keyword args or class
attributes should be relatively uncommon; but people will start to
depend on the ordering of all dicts all too easily. I want to remind
them that they are taking a risk, and their code won't be backwards


On Fri, Sep 9, 2016 at 9:52 AM, Brett Cannon <brett at python.org> wrote:
> On Fri, 9 Sep 2016 at 01:58 Antoine Pitrou <solipsis at pitrou.net> wrote:
>> On Thu, 8 Sep 2016 14:20:53 -0700
>> Victor Stinner <victor.stinner at gmail.com> wrote:
>> > 2016-09-08 13:36 GMT-07:00 Guido van Rossum <guido at python.org>:
>> > > IIUC there's one small thing we might still want to change somewhere
>> > > after 3.6b1 but before 3.6rc1: the order is not preserved when you
>> > > delete some keys and then add some other keys. Apparently PyPy has
>> > > come up with a clever solution for this, and we should probably adopt
>> > > it, but it's probably best not to hurry that for 3.6b1.
>> >
>> > Very good news: I was wrong, Raymond Hettinger confirmed that the
>> > Python 3.6 dict *already* preserves the items order in all cases. In
>> > short, Python 3.6 dict = Python 3.5 OrderedDict (in fact, OrderedDict
>> > has a few more methods).
>> Is it an official feature of the language or an implementation detail?
> It depends on the context. **kwargs is now defined to be an ordered mapping
> and PEP 520 has been updated to drop __definition_order__ and to say that
> cls.__dict__ is an ordered mapping. Otherwise we have not made dict itself
> ordered everywhere.
> And there has been discussion to rip out the C code for OrderedDict and
> change the Python code to subclass dict so it only has to provide its
> additions to the dict API.
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/guido%40python.org

--Guido van Rossum (python.org/~guido)

More information about the Python-Dev mailing list