]> granicus.if.org Git - python/commitdiff
Backport of fix to allow exception instances to be sliced once again.
authorBrett Cannon <bcannon@gmail.com>
Thu, 21 Sep 2006 18:12:15 +0000 (18:12 +0000)
committerBrett Cannon <bcannon@gmail.com>
Thu, 21 Sep 2006 18:12:15 +0000 (18:12 +0000)
Lib/test/test_exceptions.py
Misc/NEWS
Objects/exceptions.c

index 27d88a0fd5f079df7180ce05097fde5eaacf10f8..345569f679c527685fdf9e2396e668042e6b932c 100644 (file)
@@ -279,6 +279,13 @@ class ExceptionTests(unittest.TestCase):
                                               'pickled "%r", attribute "%s' %
                                               (e, checkArgName))
 
+    def testSlicing(self):
+        # Test that you can slice an exception directly instead of requiring
+        # going through the 'args' attribute.
+        args = (1, 2, 3)
+        exc = BaseException(*args)
+        self.failUnlessEqual(exc[:], args)
+
     def testKeywordArgs(self):
         # test that builtin exception don't take keyword args,
         # but user-defined subclasses can if they want
index 06bd3ac57ab0fe0ebb6eaf2177604bac39a94f92..d3e9852707e481e98aad2ffa6716789c394dd4f2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -4,6 +4,17 @@ Python News
 
 (editors: check NEWS.help for information about editing NEWS using ReST.)
 
+What's New in Python 2.5.1c1?
+=============================
+
+*Release date: XX-XXX-XXXX*
+
+Core and builtins
+-----------------
+
+- Allow exception instances to be directly sliced again.
+
+
 What's New in Python 2.5 (final)
 ================================
 
index fda2ab1e301ec82b8f80b1df2eb71eaf3ffd393c..bfe28a95c0a8db6dc725a25b7caf4be4d8ed5587 100644 (file)
@@ -190,12 +190,19 @@ BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
     return PySequence_GetItem(self->args, index);
 }
 
+static PyObject *
+BaseException_getslice(PyBaseExceptionObject *self,
+                       Py_ssize_t start, Py_ssize_t stop)
+{
+    return PySequence_GetSlice(self->args, start, stop);
+}
+
 static PySequenceMethods BaseException_as_sequence = {
     0,                      /* sq_length; */
     0,                      /* sq_concat; */
     0,                      /* sq_repeat; */
     (ssizeargfunc)BaseException_getitem,  /* sq_item; */
-    0,                      /* sq_slice; */
+    (ssizessizeargfunc)BaseException_getslice,  /* sq_slice; */
     0,                      /* sq_ass_item; */
     0,                      /* sq_ass_slice; */
     0,                      /* sq_contains; */