]> granicus.if.org Git - python/commitdiff
Allow exceptions to be directly sliced again
authorBrett Cannon <bcannon@gmail.com>
Wed, 20 Sep 2006 18:43:13 +0000 (18:43 +0000)
committerBrett Cannon <bcannon@gmail.com>
Wed, 20 Sep 2006 18:43:13 +0000 (18:43 +0000)
(e.g., ``BaseException(1,2,3)[0:2]``).

Discovered in Python 2.5.0 by Thomas Heller and reported to python-dev.  This
should be backported to 2.5 .

Misc/NEWS
Objects/exceptions.c

index 911f721f789815849e39a7eb9826a46bafc290fc..c5cc2af3a9936b4c062b3c98e5dfb889f4fe507f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 1?
 Core and builtins
 -----------------
 
+- Allow exception instances to be directly sliced again.
+
 - Bug #1551432: Exceptions do not define an explicit __unicode__ method.  This
   allows calling unicode() on exceptions classes directly to succeed.
 
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; */