Skip to content

Commit c70e003

Browse files
committed
Backport of fix to allow exception instances to be sliced once again.
1 parent 7dcdeaf commit c70e003

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lib/test/test_exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ def testAttributes(self):
279279
'pickled "%r", attribute "%s' %
280280
(e, checkArgName))
281281

282+
def testSlicing(self):
283+
# Test that you can slice an exception directly instead of requiring
284+
# going through the 'args' attribute.
285+
args = (1, 2, 3)
286+
exc = BaseException(*args)
287+
self.failUnlessEqual(exc[:], args)
288+
282289
def testKeywordArgs(self):
283290
# test that builtin exception don't take keyword args,
284291
# but user-defined subclasses can if they want

Misc/NEWS

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ Python News
44

55
(editors: check NEWS.help for information about editing NEWS using ReST.)
66

7+
What's New in Python 2.5.1c1?
8+
=============================
9+
10+
*Release date: XX-XXX-XXXX*
11+
12+
Core and builtins
13+
-----------------
14+
15+
- Allow exception instances to be directly sliced again.
16+
17+
718
What's New in Python 2.5 (final)
819
================================
920

Objects/exceptions.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,19 @@ BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
190190
return PySequence_GetItem(self->args, index);
191191
}
192192

193+
static PyObject *
194+
BaseException_getslice(PyBaseExceptionObject *self,
195+
Py_ssize_t start, Py_ssize_t stop)
196+
{
197+
return PySequence_GetSlice(self->args, start, stop);
198+
}
199+
193200
static PySequenceMethods BaseException_as_sequence = {
194201
0, /* sq_length; */
195202
0, /* sq_concat; */
196203
0, /* sq_repeat; */
197204
(ssizeargfunc)BaseException_getitem, /* sq_item; */
198-
0, /* sq_slice; */
205+
(ssizessizeargfunc)BaseException_getslice, /* sq_slice; */
199206
0, /* sq_ass_item; */
200207
0, /* sq_ass_slice; */
201208
0, /* sq_contains; */

0 commit comments

Comments
 (0)