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 @@ -12,6 +12,9 @@ What's New in Python 3.3.1?
1212Core and Builtins
1313-----------------
1414
15+ - Issue #16402: When slicing a range, fix shadowing of exceptions from
16+ __index__.
17+
1518- Issue #16336: fix input checking in the surrogatepass error handler.
1619 Patch by Serhiy Storchaka.
1720
Original file line number Diff line number Diff line change @@ -331,11 +331,11 @@ compute_slice_element(PyObject *obj)
331331 if (PyIndex_Check (obj )) {
332332 result = PyNumber_Index (obj );
333333 }
334- }
335- if ( result == NULL ) {
336- PyErr_SetString ( PyExc_TypeError ,
337- "slice indices must be integers or "
338- "None or have an __index__ method" );
334+ else {
335+ PyErr_SetString ( PyExc_TypeError ,
336+ "slice indices must be integers or "
337+ "None or have an __index__ method" );
338+ }
339339 }
340340 return result ;
341341}
You can’t perform that action at this time.
0 commit comments