You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dict order is now guaranteed, so add tests and doc for it #76518
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2018-04-04.17:36:05.905>created_at=<Date2017-12-15.18:14:10.450>labels= ['3.8', '3.7', 'tests']
title='Dict order is now guaranteed, so add tests and doc for it'updated_at=<Date2018-04-04.17:36:05.903>user='https://github.com/rhettinger'
changed the title [-]Dict order is now guaranteed, so add tests for it[/-][+]Dict order is now guaranteed, so add tests and doc for it[/+]on Dec 15, 2017
I started to add this comment to bpo-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).
Activity
[-]Dict order is now guaranteed, so add tests for it[/-][+]Dict order is now guaranteed, so add tests and doc for it[/+]methane commentedon Dec 26, 2017
FYI, Builtin dict is tested for ordering already:
cpython/Lib/test/test_ordered_dict.py
Lines 646 to 662 in 13a6c09
shangdahao commentedon Dec 28, 2017
Thanks inada, I removed the tests from the PR.
zhangyangyu commentedon Feb 2, 2018
This part needs editing too, the text and example. https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects
shangdahao commentedon Feb 4, 2018
Thanks zhang, I have updated it in the PR.
ned-deily commentedon Mar 11, 2018
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.
stevendaprano commentedon Apr 4, 2018
I started to add this comment to bpo-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:
and references to "arbitrary order" should be replaced by "insertion order". But by no means should we suggest that dicts are fundamentally orderable (sortable).
methane commentedon Apr 4, 2018
Sorry, I closed it, not Raymond.
methane commentedon Apr 4, 2018
New changeset dfbbbf1 by INADA Naoki (hui shang) in branch 'master':
bpo-32337: Update documentats about dict order (GH-4973)
dfbbbf1
miss-islington commentedon Apr 4, 2018
New changeset 9216dff by Miss Islington (bot) in branch '3.7':
bpo-32337: Update documentats about dict order (GH-4973)
9216dff
methane commentedon Apr 4, 2018
Any other known issue? May I close this issue?
ned-deily commentedon Apr 4, 2018
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.