[Python-checkins] r51951 - in python/branches/release25-maint: Lib/test/test_exceptions.py Misc/NEWS Objects/exceptions.c

brett.cannon python-checkins at python.org
Thu Sep 21 20:12:16 CEST 2006


Author: brett.cannon
Date: Thu Sep 21 20:12:15 2006
New Revision: 51951

Modified:
   python/branches/release25-maint/Lib/test/test_exceptions.py
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Objects/exceptions.c
Log:
Backport of fix to allow exception instances to be sliced once again.


Modified: python/branches/release25-maint/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_exceptions.py	(original)
+++ python/branches/release25-maint/Lib/test/test_exceptions.py	Thu Sep 21 20:12:15 2006
@@ -279,6 +279,13 @@
                                               '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

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Thu Sep 21 20:12:15 2006
@@ -4,6 +4,17 @@
 
 (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)
 ================================
 

Modified: python/branches/release25-maint/Objects/exceptions.c
==============================================================================
--- python/branches/release25-maint/Objects/exceptions.c	(original)
+++ python/branches/release25-maint/Objects/exceptions.c	Thu Sep 21 20:12:15 2006
@@ -190,12 +190,19 @@
     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; */


More information about the Python-checkins mailing list