[Python-Dev] Guarantee ordered dict literals in v3.7?

Chris Barker chris.barker at noaa.gov
Mon Nov 6 18:23:18 EST 2017


On Mon, Nov 6, 2017 at 11:23 AM, Paul G <paul at ganssle.io> wrote:

> (Of course, given that CPython's implementation is order-preserving, a
> bunch of code is probably now being written that implicitly requires on
> this detail, but at least having syntax that makes that clear would give
> people the *option* to make the assumption explicit).


This is a really key point -- a heck of a lot more people use cPython than
read the language spec. And a great deal of code is developed with a
certain level of ignorance -- try something, if it works, and your test
pass (if there are any), then you are done.

So right now, there is more an more code out there that relies on a regular
old dcit being ordered.

I've been struggling with teaching this right now -- my
written-a-couple-years ago materials talk about dicts being arbitrary
order, and then have a little demo of that fact. Now I'm teaching with
Python 3.6, and I had to add in something like:

   cPython does, in fact, preserve order with dicts, but it should be
considered an implementation detail, and not counted on ... (and by the
say, so does PyPy, and ....)"

I don't know, but I'm going to guess about 0% of my class is going to
remember that...

And if we added o{,,,} syntax it would be even worse, 'cause folks would
forget to use it, as their code wouldn't behave differently (kind of like
the 'b' flag on unix text files, or the u"string" where everything is ascii
in that string...)

in short -- we don't have a choice (unless we add an explicit randomization
as some suggested -- but that just seems perverse...)

-CHB

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171106/d9b57adb/attachment.html>


More information about the Python-Dev mailing list