1.1 --- a/lib/__builtins__/sequence.py Mon Nov 28 00:53:13 2016 +0100
1.2 +++ b/lib/__builtins__/sequence.py Mon Nov 28 00:59:41 2016 +0100
1.3 @@ -54,7 +54,7 @@
1.4 # ones.
1.5
1.6 if _isinstance(index, int):
1.7 - index = _normalise_index(index, self.__len__())
1.8 + index = _get_absolute_index(index, self.__len__())
1.9 return self.__get_single_item__(index)
1.10
1.11 # Handle slices separately.
1.12 @@ -75,7 +75,7 @@
1.13 # ones.
1.14
1.15 if _isinstance(index, int):
1.16 - index = _normalise_index(index, self.__len__())
1.17 + index = _get_absolute_index(index, self.__len__())
1.18 return self.__set_single_item__(index, value)
1.19
1.20 # Handle slices separately.
1.21 @@ -100,7 +100,7 @@
1.22 if start is None:
1.23 start = 0
1.24 else:
1.25 - start = _normalise_index(start, length)
1.26 + start = _get_absolute_index(start, length)
1.27
1.28 # Handle a null end as the first position after the end of the sequence,
1.29 # otherwise normalising any end index.
1.30 @@ -108,7 +108,7 @@
1.31 if end is None:
1.32 end = length
1.33 else:
1.34 - end = _normalise_index(end, length)
1.35 + end = _get_absolute_index(end, length)
1.36
1.37 result = []
1.38
1.39 @@ -118,6 +118,16 @@
1.40
1.41 return result
1.42
1.43 + def _check_index(self, index):
1.44 +
1.45 + """
1.46 + Check the given absolute 'index', raising an IndexError if out of
1.47 + bounds.
1.48 + """
1.49 +
1.50 + if index < 0 or index >= len(self):
1.51 + raise IndexError(index)
1.52 +
1.53 def _get_absolute_index(index, length):
1.54
1.55 """
1.56 @@ -130,12 +140,6 @@
1.57 else:
1.58 return index
1.59
1.60 -def _normalise_index(index, length):
1.61 -
1.62 - "Normalise 'index' for a collection having the specified 'length'."
1.63 -
1.64 - return _min(length, _max(0, _get_absolute_index(index, length)))
1.65 -
1.66 def _max(x, y):
1.67
1.68 "Return the maximum of 'x' and 'y'."