Author jab
Recipients gvanrossum, jab, rhettinger
Date 2016-12-08.23:00:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Since code can be clearer than prose, I just sketched this idea out in the attached patch. Please take a look at it as a minimum demonstration of the concept.


The Python standard library provides collections.OrderedDict, along with several ABCs which OrderedDict extends, such as and (as of 3.6), to enable better composability and interoperability.

Currently there is no ABC, but I wonder if there should be. OrderedMapping could provide a concrete, generic implementation of __eq__, that performed an order-sensitive comparison when passed another OrderedMapping, while performing an order-insensitive comparison when passed an unordered Mapping. Then OrderedDict could derive from OrderedMapping, inheriting its generic __eq__ implementation, rather than implementing its own __eq__ method. Currently, OrderedDict's own __eq__ implementation does ``isinstance(other, OrderedDict)`` to decide whether to perform an order-sensitive comparison, which thwarts interoperability. OrderedMapping could also derive from Reversible, signaling that classes that extend it implement __reversed__.

The interoperability gain here is not just theoretical. Several packages are published on PyPI which would be able to interoperate better if they could all extend a common OrderedMapping interface. Grant Jenks' sortedcontainers.SortedDict[1] and my own bidict.OrderedBidict[2] are two particularly popular examples.

Thanks for your consideration, and look forward to your feedback.

Date User Action Args
2016-12-08 23:00:34jabsetrecipients: + jab, gvanrossum, rhettinger
2016-12-08 23:00:34jabsetmessageid: <>
2016-12-08 23:00:34jablinkissue28912 messages
2016-12-08 23:00:34jabcreate