Skip to content

Dict comparisons insensitive to order #1788

Closed

Description

@MVrachev

Description of issue or feature request:
In #1783 we dropped support for Python 3.6 and inside this pr, we decided to drop OrderedDicts as well: e3b267e.
The argument was that inside python 3.7+ dictionaries insertion order is preserved: https://docs.python.org/3/whatsnew/3.7.html.

Even though the insertion order is preserved we should keep in mind that there are still differences between OrderedDicts and regular dictionaries like when comparing them:

>>> OrderedDict([(1,1), (2,2)]) == OrderedDict([(2,2), (1,1)]) 
False
>>> dict([(1,1), (2,2)]) == dict([(2,2), (1,1)]) 
True

The question is:
Is it a problem if we have two dictionaries with data in a different order that are not the same?

If yes we have two solutions:

  • revert e3b267e
  • inside the __eq__ implementations make sure this will happen:
>>> list(dict([(1,1), (2,2)]).keys())  == list(dict([(2,2), (1,1)]).keys())
False

or in other words where we are using dictionaries make sure when comparing them that the order makes a difference.

Activity

  1. added
    discussionDiscussions related to the design, implementation and operation of the project
    on Jan 21, 2022
  2. MVrachev commented on Jan 26, 2022

    @MVrachev
    CollaboratorAuthor

    It's good to add solve this issue with #1775.

  3. added
    backlogIssues to address with priority for current development goals
    on Jan 26, 2022
  4. self-assigned this
    on Feb 7, 2022
  5. added this to the sprint 17 milestone on Feb 9, 2022
  6. modified the milestones: sprint 17, sprint 18 on Feb 23, 2022
  7. MVrachev commented on Feb 28, 2022

    @MVrachev
    CollaboratorAuthor

    I have implemented __eq__ for all classes inside tuf/api/metadata.py and I have added a separate commit making sure order is considered during comparison where it makes sense: 6ea5372.
    That's why I think this issue is resolved.
    If there is something to be added, feel free to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backlogIssues to address with priority for current development goalsdiscussionDiscussions related to the design, implementation and operation of the project

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions