Author jab
Recipients gvanrossum, jab, rhettinger
Date 2016-12-08.23:00:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1481238034.34.0.119082165821.issue28912@psf.upfronthosting.co.za>
In-reply-to
Content
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.

Rationale:

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

Currently there is no collections.abc.OrderedMapping 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.

[1] http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html
[2] https://bidict.readthedocs.io/en/dev/other-bidict-types.html#orderedbidict
History
Date User Action Args
2016-12-08 23:00:34jabsetrecipients: + jab, gvanrossum, rhettinger
2016-12-08 23:00:34jabsetmessageid: <1481238034.34.0.119082165821.issue28912@psf.upfronthosting.co.za>
2016-12-08 23:00:34jablinkissue28912 messages
2016-12-08 23:00:34jabcreate