[issue28912] collections.abc.OrderedMapping

Joshua Bronson report at bugs.python.org
Fri Dec 9 00:18:30 EST 2016


Joshua Bronson added the comment:

Come to think of it, to be exact, rather than extending Reversible, OrderedMapping could extend a narrower interface, something like collections.abc.Ordered, along with extending Mapping. (Reversible implies Ordered, but Ordered does not imply Reversible: a singly-linked list is Ordered but not Reversible, for example.)

I guess we don't currently have Ordered because it wouldn't necessarily add any abstractmethods beyond what Iterable already provides. But it could provide a generic, concrete __eq__ implementation, something like:

class Ordered(Iterable):
    def __eq__(self, other):
        if not isinstance(other, Ordered):
            return NotImplemented
        return all(i == j for (i, j) in zip(self, other))


which is not something that any existing collections.abc Iterable currently provides.

Even if an Ordered interface that's totally empty were available in the standard library, then Iterables across diparate codebases could opt into extending it as a standard signal that they iterate over their elements in a well-defined order, and could participate in other polymorphic code. Currently we have no such standard signal, do we?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28912>
_______________________________________


More information about the Python-bugs-list mailing list