File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -312,6 +312,15 @@ def __index__(self):
312312
313313 self .assertRaises (TypeError , range , IN ())
314314
315+ # Test use of user-defined classes in slice indices.
316+ self .assertEqual (list (range (10 )[:I (5 )]), list (range (5 )))
317+
318+ with self .assertRaises (RuntimeError ):
319+ range (0 , 10 )[:IX ()]
320+
321+ with self .assertRaises (TypeError ):
322+ range (0 , 10 )[:IN ()]
323+
315324 def test_count (self ):
316325 self .assertEqual (range (3 ).count (- 1 ), 0 )
317326 self .assertEqual (range (3 ).count (0 ), 1 )
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ What's New in Python 3.2.4
1010Core and Builtins
1111-----------------
1212
13+ - Issue #16402: When slicing a range, fix shadowing of exceptions from
14+ __index__.
15+
1316- Issue #16336: fix input checking in the surrogatepass error handler.
1417 Patch by Serhiy Storchaka.
1518
Original file line number Diff line number Diff line change @@ -330,11 +330,11 @@ compute_slice_element(PyObject *obj)
330330 if (PyIndex_Check (obj )) {
331331 result = PyNumber_Index (obj );
332332 }
333- }
334- if ( result == NULL ) {
335- PyErr_SetString ( PyExc_TypeError ,
336- "slice indices must be integers or "
337- "None or have an __index__ method" );
333+ else {
334+ PyErr_SetString ( PyExc_TypeError ,
335+ "slice indices must be integers or "
336+ "None or have an __index__ method" );
337+ }
338338 }
339339 return result ;
340340}
You can’t perform that action at this time.
0 commit comments