mirror of https://github.com/python/cpython
Issue #16402: Merge fix from 3.2
This commit is contained in:
commit
1321edaa55
|
@ -312,6 +312,15 @@ class RangeTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertRaises(TypeError, range, IN())
|
self.assertRaises(TypeError, range, IN())
|
||||||
|
|
||||||
|
# Test use of user-defined classes in slice indices.
|
||||||
|
self.assertEqual(list(range(10)[:I(5)]), list(range(5)))
|
||||||
|
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
range(0, 10)[:IX()]
|
||||||
|
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
range(0, 10)[:IN()]
|
||||||
|
|
||||||
def test_count(self):
|
def test_count(self):
|
||||||
self.assertEqual(range(3).count(-1), 0)
|
self.assertEqual(range(3).count(-1), 0)
|
||||||
self.assertEqual(range(3).count(0), 1)
|
self.assertEqual(range(3).count(0), 1)
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 3.3.1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #16402: When slicing a range, fix shadowing of exceptions from
|
||||||
|
__index__.
|
||||||
|
|
||||||
- Issue #16336: fix input checking in the surrogatepass error handler.
|
- Issue #16336: fix input checking in the surrogatepass error handler.
|
||||||
Patch by Serhiy Storchaka.
|
Patch by Serhiy Storchaka.
|
||||||
|
|
||||||
|
|
|
@ -331,11 +331,11 @@ compute_slice_element(PyObject *obj)
|
||||||
if (PyIndex_Check(obj)) {
|
if (PyIndex_Check(obj)) {
|
||||||
result = PyNumber_Index(obj);
|
result = PyNumber_Index(obj);
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
if (result == NULL) {
|
PyErr_SetString(PyExc_TypeError,
|
||||||
PyErr_SetString(PyExc_TypeError,
|
"slice indices must be integers or "
|
||||||
"slice indices must be integers or "
|
"None or have an __index__ method");
|
||||||
"None or have an __index__ method");
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue