@@ -161,7 +161,7 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
161
161
{
162
162
if ( ! Runtime . PyInt_Check ( idx ) )
163
163
{
164
- return Exceptions . RaiseTypeError ( "array index is not an integer" ) ;
164
+ return RaiseTypeError ( idx ) ;
165
165
}
166
166
index = Runtime . PyInt_AsLong ( idx ) ;
167
167
@@ -205,7 +205,7 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
205
205
IntPtr op = Runtime . PyTuple_GetItem ( idx , i ) ;
206
206
if ( ! Runtime . PyInt_Check ( op ) )
207
207
{
208
- return Exceptions . RaiseTypeError ( $ "array index { i } is not an integer" ) ;
208
+ return RaiseTypeError ( op ) ;
209
209
}
210
210
index = Runtime . PyInt_AsLong ( op ) ;
211
211
@@ -263,7 +263,7 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
263
263
{
264
264
if ( ! Runtime . PyInt_Check ( idx ) )
265
265
{
266
- Exceptions . RaiseTypeError ( "array index is not an integer" ) ;
266
+ RaiseTypeError ( idx ) ;
267
267
return - 1 ;
268
268
}
269
269
index = Runtime . PyInt_AsLong ( idx ) ;
@@ -306,7 +306,7 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
306
306
IntPtr op = Runtime . PyTuple_GetItem ( idx , i ) ;
307
307
if ( ! Runtime . PyInt_Check ( op ) )
308
308
{
309
- Exceptions . RaiseTypeError ( $ "array index { i } is not an integer" ) ;
309
+ RaiseTypeError ( op ) ;
310
310
return - 1 ;
311
311
}
312
312
index = Runtime . PyInt_AsLong ( op ) ;
@@ -338,6 +338,11 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
338
338
return 0 ;
339
339
}
340
340
341
+ private static IntPtr RaiseTypeError ( IntPtr idx )
342
+ {
343
+ string tpName = Runtime . PyObject_GetTypeName ( idx ) ;
344
+ return Exceptions . RaiseTypeError ( $ "array index has type { tpName } , expected an integer") ;
345
+ }
341
346
342
347
/// <summary>
343
348
/// Implements __contains__ for array types.
0 commit comments