[Python-checkins] cpython (merge 3.2 -> 3.3): Issue #16402: Merge fix from 3.2

mark.dickinson python-checkins at python.org
Sun Nov 4 12:48:13 CET 2012


http://hg.python.org/cpython/rev/2b656a2cf7ef
changeset: 80237:2b656a2cf7ef
branch: 3.3
parent: 80234:7fde4b4f7e56
parent: 80236:94d15358ad6e
user: Mark Dickinson <mdickinson at enthought.com>
date: Sun Nov 04 11:47:05 2012 +0000
summary:
 Issue #16402: Merge fix from 3.2
files:
 Lib/test/test_range.py | 9 +++++++++
 Misc/NEWS | 3 +++
 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
--- a/Lib/test/test_range.py
+++ b/Lib/test/test_range.py
@@ -312,6 +312,15 @@
 
 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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@
 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
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -331,11 +331,11 @@
 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;
 }
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /