Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dict order is now guaranteed, so add tests and doc for it #76518

Closed
rhettinger opened this issue Dec 15, 2017 · 11 comments
Closed

Dict order is now guaranteed, so add tests and doc for it #76518

rhettinger opened this issue Dec 15, 2017 · 11 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes tests Tests in the Lib/test dir

Comments

@rhettinger
Copy link
Contributor

BPO 32337
Nosy @rhettinger, @ned-deily, @stevendaprano, @methane, @zhangyangyu, @shangdahao, @miss-islington
PRs
  • bpo-32337: Update tutorial and documentation related with dict order. #4973
  • [3.7] bpo-32337: Update documentats about dict order (GH-4973) #6368
  • 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 = None
    closed_at = <Date 2018-04-04.17:36:05.905>
    created_at = <Date 2017-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 = <Date 2018-04-04.17:36:05.903>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2018-04-04.17:36:05.903>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-04-04.17:36:05.905>
    closer = 'ned.deily'
    components = ['Tests']
    creation = <Date 2017-12-15.18:14:10.450>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32337
    keywords = ['patch']
    message_count = 11.0
    messages = ['309060', '309114', '311490', '311585', '313624', '314916', '314917', '314918', '314920', '314930', '314943']
    nosy_count = 7.0
    nosy_names = ['rhettinger', 'ned.deily', 'steven.daprano', 'methane', 'xiang.zhang', 'shangdahao', 'miss-islington']
    pr_nums = ['4973', '6368']
    priority = None
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32337'
    versions = ['Python 3.7', 'Python 3.8']

    @rhettinger rhettinger self-assigned this Dec 15, 2017
    @rhettinger rhettinger added 3.7 (EOL) end of life tests Tests in the Lib/test dir labels Dec 15, 2017
    @rhettinger 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 Dec 15, 2017
    @methane
    Copy link
    Member

    methane commented Dec 26, 2017

    FYI, Builtin dict is tested for ordering already:

    class CPythonBuiltinDictTests(unittest.TestCase):
    """Builtin dict preserves insertion order.
    Reuse some of tests in OrderedDict selectively.
    """
    module = builtins
    OrderedDict = dict
    for method in (
    "test_init test_update test_abc test_clear test_delitem " +
    "test_setitem test_detect_deletion_during_iteration " +
    "test_popitem test_reinsert test_override_update " +
    "test_highly_nested test_highly_nested_subclass " +
    "test_delitem_hash_collision ").split():
    setattr(CPythonBuiltinDictTests, method, getattr(OrderedDictTests, method))
    del method

    @shangdahao
    Copy link
    Mannequin

    shangdahao mannequin commented Dec 28, 2017

    Thanks inada, I removed the tests from the PR.

    @zhangyangyu
    Copy link
    Member

    This part needs editing too, the text and example. https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects

    @shangdahao
    Copy link
    Mannequin

    shangdahao mannequin commented Feb 4, 2018

    Thanks zhang, I have updated it in the PR.

    @rhettinger rhettinger removed their assignment Feb 4, 2018
    @ned-deily
    Copy link
    Member

    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
    Copy link
    Member

    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).

    @methane
    Copy link
    Member

    methane commented Apr 4, 2018

    I started to add this comment to bpo-33218 but Raymond closed that ticket while I was editing it.

    Sorry, I closed it, not Raymond.

    @methane
    Copy link
    Member

    methane commented 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
    Copy link
    Contributor

    New changeset 9216dff by Miss Islington (bot) in branch '3.7':
    bpo-32337: Update documentats about dict order (GH-4973)
    9216dff

    @methane
    Copy link
    Member

    methane commented Apr 4, 2018

    Any other known issue? May I close this issue?

    @ned-deily
    Copy link
    Member

    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.

    @ned-deily ned-deily added the 3.8 only security fixes label Apr 4, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes tests Tests in the Lib/test dir
    Projects
    None yet
    Development

    No branches or pull requests

    7 participants