Skip to content

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

Closed

Description

@rhettinger
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']

    Activity

    1. self-assigned this
      on Dec 15, 2017
    2. 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
    3. methane commented on Dec 26, 2017

      @methane
      Member

      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

    4. shangdahao commented on Dec 28, 2017

      shangdahaomannequin
      Mannequin

      Thanks inada, I removed the tests from the PR.

    5. zhangyangyu commented on Feb 2, 2018

      @zhangyangyu
      Member

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

    6. shangdahao commented on Feb 4, 2018

      shangdahaomannequin
      Mannequin

      Thanks zhang, I have updated it in the PR.

    7. removed their assignment
      on Feb 4, 2018
    8. ned-deily commented on Mar 11, 2018

      @ned-deily
      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.

    9. stevendaprano commented on Apr 4, 2018

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

    10. methane commented on Apr 4, 2018

      @methane
      Member

      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.

    11. methane commented on Apr 4, 2018

      @methane
      Member

      New changeset dfbbbf1 by INADA Naoki (hui shang) in branch 'master':
      bpo-32337: Update documentats about dict order (GH-4973)
      dfbbbf1

    12. miss-islington commented on Apr 4, 2018

      @miss-islington
      Contributor

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

    13. methane commented on Apr 4, 2018

      @methane
      Member

      Any other known issue? May I close this issue?

    14. ned-deily commented on Apr 4, 2018

      @ned-deily
      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.

    15. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of life3.8 (EOL)end of lifetestsTests in the Lib/test dir

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions