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 <rep...@bugs.python.org>
<http://bugs.python.org/issue28912>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to