1.1 --- a/lib/__builtins__/sequence.py Wed Nov 30 18:41:59 2016 +0100
1.2 +++ b/lib/__builtins__/sequence.py Wed Nov 30 18:42:37 2016 +0100
1.3 @@ -25,6 +25,16 @@
1.4
1.5 "A common base class for sequence types."
1.6
1.7 + def _check_index(self, index):
1.8 +
1.9 + """
1.10 + Check the given absolute 'index', raising an IndexError if out of
1.11 + bounds.
1.12 + """
1.13 +
1.14 + if index < 0 or index >= len(self):
1.15 + raise IndexError(index)
1.16 +
1.17 def _str(self, opening, closing):
1.18
1.19 "Serialise this object with the given 'opening' and 'closing' strings."
1.20 @@ -147,15 +157,29 @@
1.21
1.22 return result
1.23
1.24 - def _check_index(self, index):
1.25 + def __eq__(self, other):
1.26 +
1.27 + "Return whether this sequence is equal to 'other'."
1.28 +
1.29 + # Sequences must have equal lengths to be equal.
1.30 +
1.31 + n = self.__len__()
1.32 + if len(other) != n:
1.33 + return False
1.34
1.35 - """
1.36 - Check the given absolute 'index', raising an IndexError if out of
1.37 - bounds.
1.38 - """
1.39 + i = 0
1.40 + while i < n:
1.41 + if self.__getitem__(i) != other.__getitem__(i):
1.42 + return False
1.43 + i += 1
1.44
1.45 - if index < 0 or index >= len(self):
1.46 - raise IndexError(index)
1.47 + return True
1.48 +
1.49 + def __ne__(self, other):
1.50 +
1.51 + "Return whether this sequence is not equal to 'other'."
1.52 +
1.53 + return not self.__eq__(other)
1.54
1.55 def _get_absolute_index(index, length):
1.56