classification
Title: Dict order is now guaranteed, so add tests and doc for it
Type: Stage: resolved
Components: Tests Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: inada.naoki, miss-islington, ned.deily, rhettinger, shangdahao, steven.daprano, xiang.zhang
Priority: Keywords: patch

Created on 2017-12-15 18:14 by rhettinger, last changed 2018-04-04 17:36 by ned.deily. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4973 merged shangdahao, 2017-12-22 10:14
PR 6368 merged miss-islington, 2018-04-04 04:56
Messages (11)
msg309060 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2017-12-26 11:25
FYI, Builtin dict is tested for ordering already:
https://github.com/python/cpython/blob/13a6c098c215921e35004f9d3a9b70f601e56500/Lib/test/test_ordered_dict.py#L646-L662
msg309114 - (view) Author: shangdahao (shangdahao) * Date: 2017-12-28 01:12
Thanks inada, I removed the tests from the PR.
msg311490 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2018-02-02 13:38
This part needs editing too, the text and example. https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects
msg311585 - (view) Author: shangdahao (shangdahao) * Date: 2018-02-04 04:13
Thanks zhang, I have updated it in the PR.
msg313624 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-03-11 21:42
Raymond, do you want to review the current state of the PR before 3.7.0b4?  Otherwise, I'll probably ask that it be merged as is.
msg314916 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-04-04 04:41
I started to add this comment to #33218 but Raymond closed that ticket while I was editing it.

In 3.6, dicts preserving insertion order remains an implementation detail that cannot be relied on. It only becomes a guarantee in 3.7.

Even in 3.7, I think that it remains best to think of dicts as fundamentally unordered. Dicts might preserve insertion order, but there's no interface for extracting the n-th item, or re-ordering the keys into some alternative order, and for the purposes of equality comparisons, the order is ignored.

I propose changing the description from "It is best to think of a dictionary as an unordered set of key: value pairs" to something like:


    Dicts are an otherwise unordered set of key:value pairs
    that remember the order keys were inserted.


and references to "arbitrary order" should be replaced by "insertion order". But by no means should we suggest that dicts are fundamentally orderable (sortable).
msg314917 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2018-04-04 04:45
> I started to add this comment to #33218 but Raymond closed that ticket while I was editing it.

Sorry, I closed it, not Raymond.
msg314918 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2018-04-04 04:55
New changeset dfbbbf16f9aab82330c634913441b5ac73267d9c by INADA Naoki (hui shang) in branch 'master':
bpo-32337: Update documentats about dict order (GH-4973)
https://github.com/python/cpython/commit/dfbbbf16f9aab82330c634913441b5ac73267d9c
msg314920 - (view) Author: miss-islington (miss-islington) Date: 2018-04-04 05:01
New changeset 9216dffbc8a2aa62789f81f51f64bc1ec7bf6883 by Miss Islington (bot) in branch '3.7':
bpo-32337: Update documentats about dict order (GH-4973)
https://github.com/python/cpython/commit/9216dffbc8a2aa62789f81f51f64bc1ec7bf6883
msg314930 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2018-04-04 13:55
Any other known issue?  May I close this issue?
msg314943 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-04-04 17:36
Thanks for doing this!  Let's close it.  If comments arise prior to its release in 370b4, we can reopen, otherwise please open a new issue.
History
Date User Action Args
2018-04-04 17:36:05ned.deilysetstatus: open -> closed
priority: deferred blocker ->
versions: + Python 3.8
messages: + msg314943

resolution: fixed
stage: patch review -> resolved
2018-04-04 13:55:21inada.naokisetmessages: + msg314930
2018-04-04 05:01:48miss-islingtonsetnosy: + miss-islington
messages: + msg314920
2018-04-04 04:56:18miss-islingtonsetpull_requests: + pull_request6079
2018-04-04 04:55:08inada.naokisetmessages: + msg314918
2018-04-04 04:45:08inada.naokisetmessages: + msg314917
2018-04-04 04:41:29steven.dapranosetnosy: + steven.daprano
messages: + msg314916
2018-04-04 04:24:58inada.naokilinkissue33218 superseder
2018-04-03 06:12:08inada.naokiunlinkissue32360 dependencies
2018-03-21 09:24:43eric.smithunlinkissue32506 dependencies
2018-03-11 21:42:35ned.deilysetpriority: release blocker -> deferred blocker

messages: + msg313624
2018-03-11 07:06:10serhiy.storchakaunlinkissue32338 dependencies
2018-03-11 07:05:34serhiy.storchakasetpriority: normal -> release blocker
nosy: + ned.deily
2018-02-04 05:08:20rhettingersetassignee: rhettinger ->
2018-02-04 04:13:44shangdahaosetmessages: + msg311585
2018-02-02 13:38:47xiang.zhangsetnosy: + xiang.zhang
messages: + msg311490
2018-01-29 20:39:31rhettingerunlinkissue32336 dependencies
2018-01-26 07:39:38xiang.zhanglinkissue32673 superseder
2018-01-07 07:47:40serhiy.storchakalinkissue32506 dependencies
2017-12-28 01:12:23shangdahaosetnosy: + shangdahao
messages: + msg309114
2017-12-26 11:25:14inada.naokisetnosy: + inada.naoki
messages: + msg309060
2017-12-22 10:14:56shangdahaosetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request4864
2017-12-18 09:53:57serhiy.storchakalinkissue32360 dependencies
2017-12-18 09:53:44serhiy.storchakalinkissue32338 dependencies
2017-12-18 09:53:28serhiy.storchakalinkissue32336 dependencies
2017-12-15 21:35:31rhettingersettitle: Dict order is now guaranteed, so add tests for it -> Dict order is now guaranteed, so add tests and doc for it
2017-12-15 18:14:10rhettingercreate