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

Guido van Rossum guido at python.org
Thu Dec 14 21:24:50 EST 2017


Oh, I just found
https://mail.python.org/pipermail/python-dev/2017-November/150323.html so I
already know what you think: we should go with "dicts preserve insertion
order" rather than "dicts preserve insertion order until the first
deletion". I guess we should wait for Serhiy to confirm that he's okay with
this.

On Thu, Dec 14, 2017 at 6:20 PM, Guido van Rossum <guido at python.org> wrote:

> I'm in favor of stating that dict keeps order as part of the language spec.
>
> However re-reading https://mail.python.org/pipermail/python-dev/2017-
> November/150381.html there's still a point of debate: should it be
> allowed if dict reorders  after deletion (presumably as a result of a
> rehash)? I'm in favor of prescribing that the order should be preserved
> even in that case, but I realize there's additional implementation work to
> be done. Inada-san, what do you think of this?
>
> --Guido
>
> On Thu, Dec 14, 2017 at 6:03 PM, INADA Naoki <songofacandy at gmail.com>
> wrote:
>
>> Hi, folks.
>>
>> TLDR, was the final decision made already?
>>
>> If "dict keeps insertion order" is not language spec and we
>> continue to recommend people to use OrderedDict to keep
>> order, I want to optimize OrderedDict for creation/iteration
>> and memory usage.  (See https://bugs.python.org/issue31265#msg301942 )
>>
>> If dict ordering is language spec, I'll stop the effort and
>> use remaining time to another optimizations.
>>
>> My thought is, +1 to make it language spec.
>>
>> * PHP (PHP 7.2 interpreter is faster than Python) keeps insertion order.
>>   So even we make it language spec, I think we have enough room
>>   to optimize.
>>
>> * It can make stop discussion like "Does X keeps insertion order?
>>   It's language spec?", "What about Y? Z?".  Everything on top of dict
>>   keeps insertion order.  It's simple to learn and explain.
>>
>> Regards,
>> INADA Naoki  <songofacandy at gmail.com>
>>
>>
>> On Sun, Nov 5, 2017 at 3:35 AM, Guido van Rossum <guido at python.org>
>> wrote:
>> > This sounds reasonable -- I think when we introduced this in 3.6 we were
>> > worried that other implementations (e.g. Jython) would have a problem
>> with
>> > this, but AFAIK they've reported back that they can do this just fine.
>> So
>> > let's just document this as a language guarantee.
>> >
>> > On Sat, Nov 4, 2017 at 10:30 AM, Stefan Krah <stefan at bytereef.org>
>> wrote:
>> >>
>> >>
>> >> Hello,
>> >>
>> >> would it be possible to guarantee that dict literals are ordered in
>> v3.7?
>> >>
>> >>
>> >> The issue is well-known and the workarounds are tedious, example:
>> >>
>> >>
>> >> https://mail.python.org/pipermail/python-ideas/2015-December
>> /037423.html
>> >>
>> >>
>> >> If the feature is guaranteed now, people can rely on it around v3.9.
>> >>
>> >>
>> >>
>> >> Stefan Krah
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> 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)
>> >
>> > _______________________________________________
>> > 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/songofaca
>> ndy%40gmail.com
>> >
>>
>
>
>
> --
> --Guido van Rossum (python.org/~guido)
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171214/159a9ae7/attachment.html>


More information about the Python-Dev mailing list