This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger, socketpair
Date 2021-04-02.02:41:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1617331313.24.0.936732199195.issue43691@roundup.psfhosted.org>
In-reply-to
Content
> There are no specifications regarding the question.

From the OrderedDict docs:

"""
Equality tests between OrderedDict objects are order-sensitive and are implemented as list(od1.items())==list(od2.items()). Equality tests between OrderedDict objects and other Mapping objects are order-insensitive like regular dictionaries. This allows OrderedDict objects to be substituted anywhere a regular dictionary is used.
"""

Also, there are tests to verify these behaviors.  From Lib/test/test_ordered_dict.py:

    def test_equality(self):
        OrderedDict = self.OrderedDict
        pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
        shuffle(pairs)
        od1 = OrderedDict(pairs)
        od2 = OrderedDict(pairs)
        self.assertEqual(od1, od2)          # same order implies equality
        pairs = pairs[2:] + pairs[:2]
        od2 = OrderedDict(pairs)
        self.assertNotEqual(od1, od2)       # different order implies inequality
        # comparison to regular dict is not order sensitive
        self.assertEqual(od1, dict(od2))
        self.assertEqual(dict(od2), od1)
        # different length implied inequality
        self.assertNotEqual(od1, OrderedDict(pairs[:-1]))



> Raising exception is the best thing since it will show 
> real bug in applications.

Changing the implementation now will break correct code that relies the documented behavior.  The change would also violate an intentional day one design goal to have ordered dictionaries be substitutable for regular dicts in existing code that may not have any concept of order.  Per PEP 372:

"""
Is the ordered dict a dict subclass? Why?

Yes. Like defaultdict, an ordered dictionary subclasses dict. Being a dict subclass make some of the methods faster (like __getitem__ and __len__). More importantly, being a dict subclass lets ordered dictionaries be usable with tools like json that insist on having dict inputs by testing isinstance(d, dict)
"""



> I don't agree.

That's not relevant.  The time to debate the merits of this API passed 13 years ago.  Guido made the final decision on the equality logic.  And now that the code is deployed and widely adopted, it is far too late to change it.
History
Date User Action Args
2021-04-02 02:41:53rhettingersetrecipients: + rhettinger, socketpair
2021-04-02 02:41:53rhettingersetmessageid: <1617331313.24.0.936732199195.issue43691@roundup.psfhosted.org>
2021-04-02 02:41:53rhettingerlinkissue43691 messages
2021-04-02 02:41:52rhettingercreate