diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2012-11-04 11:47:05 (GMT) |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2012-11-04 11:47:05 (GMT) |
commit | 1321edaa55a8df94e739e6ea5e9e658f2b7bfcc2 (patch) | |
tree | 987c8b62c47466683905620c7574bc7b2e3f37a9 | |
parent | 7ce22d19403873d590bdda78b721e15510132d16 (diff) | |
parent | 8cd1c7681d86fd3d32096f2d927d3f5014d58c36 (diff) | |
download | cpython-1321edaa55a8df94e739e6ea5e9e658f2b7bfcc2.zip cpython-1321edaa55a8df94e739e6ea5e9e658f2b7bfcc2.tar.gz cpython-1321edaa55a8df94e739e6ea5e9e658f2b7bfcc2.tar.bz2 |
Issue #16402: Merge fix from 3.2
-rw-r--r-- | Lib/test/test_range.py | 9 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/rangeobject.c | 10 |
3 files changed, 17 insertions, 5 deletions
diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py index f18046d..2a13bfe 100644 --- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -312,6 +312,15 @@ class RangeTest(unittest.TestCase): 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): self.assertEqual(range(3).count(-1), 0) self.assertEqual(range(3).count(0), 1) @@ -12,6 +12,9 @@ What's New in Python 3.3.1? 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. Patch by Serhiy Storchaka. diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 68d5636..214b455 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -331,11 +331,11 @@ compute_slice_element(PyObject *obj) if (PyIndex_Check(obj)) { result = PyNumber_Index(obj); } - } - if (result == NULL) { - PyErr_SetString(PyExc_TypeError, - "slice indices must be integers or " - "None or have an __index__ method"); + else { + PyErr_SetString(PyExc_TypeError, + "slice indices must be integers or " + "None or have an __index__ method"); + } } return result; } |