File tree 1 file changed +11
-3
lines changed 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -269,12 +269,20 @@ impl TryFromBorrowedObject for SequenceIndex {
269
269
fn try_from_borrowed_object ( vm : & VirtualMachine , obj : & PyObject ) -> PyResult < Self > {
270
270
if let Some ( i) = obj. payload :: < PyInt > ( ) {
271
271
// TODO: number protocol
272
- i. try_to_primitive ( vm) . map ( Self :: Int )
272
+ i. try_to_primitive ( vm)
273
+ . map_err ( |_| {
274
+ vm. new_index_error ( "cannot fit 'int' into an index-sized integer" . to_owned ( ) )
275
+ } )
276
+ . map ( Self :: Int )
273
277
} else if let Some ( slice) = obj. payload :: < PySlice > ( ) {
274
278
slice. to_saturated ( vm) . map ( Self :: Slice )
275
- } else if let Some ( index ) = vm. to_index_opt ( obj. to_owned ( ) ) {
279
+ } else if let Some ( i ) = vm. to_index_opt ( obj. to_owned ( ) ) {
276
280
// TODO: __index__ for indice is no more supported?
277
- index?. try_to_primitive ( vm) . map ( Self :: Int )
281
+ i?. try_to_primitive ( vm)
282
+ . map_err ( |_| {
283
+ vm. new_index_error ( "cannot fit 'int' into an index-sized integer" . to_owned ( ) )
284
+ } )
285
+ . map ( Self :: Int )
278
286
} else {
279
287
Err ( vm. new_type_error ( format ! (
280
288
"indices must be integers or slices or classes that override __index__ operator, not '{}'" ,
You can’t perform that action at this time.
0 commit comments