File tree 1 file changed +8
-3
lines changed 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,12 @@ pub trait PySliceableSequence {
13
13
fn len ( & self ) -> usize ;
14
14
fn get_pos ( & self , p : i32 ) -> usize {
15
15
if p < 0 {
16
- self . len ( ) - ( ( -p) as usize )
16
+ if -p as usize > self . len ( ) {
17
+ // return something that is out of bounds so get_item raises an IndexError
18
+ self . len ( ) + 1
19
+ } else {
20
+ self . len ( ) - ( ( -p) as usize )
21
+ }
17
22
} else if p as usize > self . len ( ) {
18
23
// This is for the slicing case where the end element is greater than the length of the
19
24
// sequence
@@ -78,8 +83,8 @@ pub fn get_item(
78
83
let obj = elements[ pos_index] . clone ( ) ;
79
84
Ok ( obj)
80
85
} else {
81
- let value_error = vm. context ( ) . exceptions . value_error . clone ( ) ;
82
- Err ( vm. new_exception ( value_error , "Index out of bounds!" . to_string ( ) ) )
86
+ let index_error = vm. context ( ) . exceptions . index_error . clone ( ) ;
87
+ Err ( vm. new_exception ( index_error , "Index out of bounds!" . to_string ( ) ) )
83
88
}
84
89
}
85
90
PyObjectPayload :: Slice {
You can’t perform that action at this time.
0 commit comments