Skip to content

Commit 6d91be3

Browse files
committed
- Issue 2379: Raise a Py3K warning for __getitem__ or __getslice__ on
exception instances.
1 parent 0bfc896 commit 6d91be3

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 2?
1212
Core and builtins
1313
-----------------
1414

15+
- Issue 2379: Raise a Py3K warning for __getitem__ or __getslice__ on
16+
exception instances.
17+
1518
- Issue #2371: Add a Py3k warning when catching an exception that
1619
doesn't derive from BaseException. Issue #2341: Add a Py3k warning
1720
when raising an exception that doesn't derive from BaseException.

Objects/exceptions.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,25 @@ static PyMethodDef BaseException_methods[] = {
189189
static PyObject *
190190
BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
191191
{
192+
if (Py_Py3kWarningFlag) {
193+
if (PyErr_Warn(PyExc_DeprecationWarning,
194+
"In 3.x, __getitem__ is not supported for exception "
195+
"classes, use args attribute") == -1)
196+
return NULL;
197+
}
192198
return PySequence_GetItem(self->args, index);
193199
}
194200

195201
static PyObject *
196202
BaseException_getslice(PyBaseExceptionObject *self,
197203
Py_ssize_t start, Py_ssize_t stop)
198204
{
205+
if (Py_Py3kWarningFlag) {
206+
if (PyErr_Warn(PyExc_DeprecationWarning,
207+
"In 3.x, __getslice__ is not supported for exception "
208+
"classes, use args attribute") == -1)
209+
return NULL;
210+
}
199211
return PySequence_GetSlice(self->args, start, stop);
200212
}
201213

0 commit comments

Comments
 (0)