mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
- Issue 2379: Raise a Py3K warning for __getitem__ or __getslice__ on
exception instances.
This commit is contained in:
parent
0bfc896979
commit
6d91be3758
2 changed files with 15 additions and 0 deletions
|
|
@ -189,6 +189,12 @@ static PyMethodDef BaseException_methods[] = {
|
|||
static PyObject *
|
||||
BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
|
||||
{
|
||||
if (Py_Py3kWarningFlag) {
|
||||
if (PyErr_Warn(PyExc_DeprecationWarning,
|
||||
"In 3.x, __getitem__ is not supported for exception "
|
||||
"classes, use args attribute") == -1)
|
||||
return NULL;
|
||||
}
|
||||
return PySequence_GetItem(self->args, index);
|
||||
}
|
||||
|
||||
|
|
@ -196,6 +202,12 @@ static PyObject *
|
|||
BaseException_getslice(PyBaseExceptionObject *self,
|
||||
Py_ssize_t start, Py_ssize_t stop)
|
||||
{
|
||||
if (Py_Py3kWarningFlag) {
|
||||
if (PyErr_Warn(PyExc_DeprecationWarning,
|
||||
"In 3.x, __getslice__ is not supported for exception "
|
||||
"classes, use args attribute") == -1)
|
||||
return NULL;
|
||||
}
|
||||
return PySequence_GetSlice(self->args, start, stop);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue