File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -106,13 +106,16 @@ def slice_indices(slice_obj, size):
106106 return (start , stop , step )
107107
108108
109- def _adjust_index (n , size , raise_index_error = True ):
109+ def _adjust_index (i , size , raise_index_error = True ):
110+ n = i
110111 if n < 0 :
111112 n += size
112113
113114 if raise_index_error :
114115 if n < 0 :
115- raise IndexError ("Out of range" )
116+ raise IndexError ("Index %d out of bounds" % (i ,))
117+ if n >= size :
118+ raise IndexError ("Index %d out of bounds" % (i ,))
116119
117120 if n > size :
118121 n = size
@@ -219,11 +222,8 @@ def __init__(self, *components):
219222 self .length *= c_len
220223
221224 def get_item (self , i , d = None ):
225+ i = _adjust_index (i , self .length )
222226 result = []
223- if i < 0 :
224- i += self .length
225- if i < 0 or i >= self .length :
226- raise IndexError ("Index %d out of bounds" % (i ,))
227227
228228 for c , c_len in self .list_lengths :
229229 i , mod = divmod (i , c_len )
You can’t perform that action at this time.
0 commit comments