# HG changeset patch # User Paul Boddie # Date 1480527757 -3600 # Node ID 299f7c37ac6ea97d218eb66a63df0f93532c9cd9 # Parent ea96958037c684cc0d49d5f6b9e8210bff298275 Made sequences comparable. diff -r ea96958037c6 -r 299f7c37ac6e lib/__builtins__/sequence.py --- a/lib/__builtins__/sequence.py Wed Nov 30 18:41:59 2016 +0100 +++ b/lib/__builtins__/sequence.py Wed Nov 30 18:42:37 2016 +0100 @@ -25,6 +25,16 @@ "A common base class for sequence types." + def _check_index(self, index): + + """ + Check the given absolute 'index', raising an IndexError if out of + bounds. + """ + + if index < 0 or index >= len(self): + raise IndexError(index) + def _str(self, opening, closing): "Serialise this object with the given 'opening' and 'closing' strings." @@ -147,15 +157,29 @@ return result - def _check_index(self, index): + def __eq__(self, other): + + "Return whether this sequence is equal to 'other'." + + # Sequences must have equal lengths to be equal. + + n = self.__len__() + if len(other) != n: + return False - """ - Check the given absolute 'index', raising an IndexError if out of - bounds. - """ + i = 0 + while i < n: + if self.__getitem__(i) != other.__getitem__(i): + return False + i += 1 - if index < 0 or index >= len(self): - raise IndexError(index) + return True + + def __ne__(self, other): + + "Return whether this sequence is not equal to 'other'." + + return not self.__eq__(other) def _get_absolute_index(index, length):