On Sat, 4 Jul 2020 at 12:51, Random832 <random...@fastmail.com> wrote:
> On Fri, Jul 3, 2020, at 03:57, Wes Turner wrote: > > Can a Sequence be infinite? If so, an equality test of two > > nonterminating sequences would be a nonterminating operation. > > I think not - an infinite sequence would make len, contains, and reversed > ill-defined (it also wouldn't allow certain kinds of slices) > > > Do Sized and *Reversible* imply that a sequence terminates? > > Could __len__ return inf? > > __len__ must return an integer. > > > Perhaps `Ordered` is a requisite condition for defining a comparator > > for Sequences. > > `OrderedSequence`? > > > > Are there unordered Sequences for which a default `__eq__` / `__cmp__` > > (et. al) would be wrong or inappropriate? > > I don't think so [index as a mixin implies being ordered, i think]... the > bigger problem is the one I mentioned earlier, that allowing comparison > between sequences of different types is inconsistent with tuple and list. > As far as types are concerned, the `__eq__` should worry about it - just Sequences that are a subtype of other, or the other being a subtype of one, should be able to compare equal (As happens with lists and tuples as well: subclasses of both will compare equal to base lists and tuples with the same content.). The code for that is on my first reply to Guido, above: if not issubclass(type(other), type(self)) and not issubclass(type(self), type(other)): return False I am actually using that on the file that motivated me sending the first e-mail here -as it makes sense in that project.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/IVQHP3XAHTNCVAOJQ3BCYXCZU5ZJS4QK/ Code of Conduct: http://python.org/psf/codeofconduct/