]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- Issue 2379: Raise a Py3K warning for __getitem__ or __getslice__ on
authorGuido van Rossum <guido@python.org>
Tue, 18 Mar 2008 04:42:22 +0000 (04:42 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 18 Mar 2008 04:42:22 +0000 (04:42 +0000)
  exception instances.

Misc/NEWS
Objects/exceptions.c

index 5436c252130d8684e14a473bb18c5e1657675ab2..2975c1530b1a34c6a0c0fcd5442597b81f0d8b83 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 2?
 Core and builtins
 -----------------
 
+- Issue 2379: Raise a Py3K warning for __getitem__ or __getslice__ on
+  exception instances.
+
 - Issue #2371: Add a Py3k warning when catching an exception that
   doesn't derive from BaseException.  Issue #2341: Add a Py3k warning
   when raising an exception that doesn't derive from BaseException.
index b1d5d0b6d5097ffdb90a3202b80d38b25d73126c..aa9f51692161f13a604752765d90080d2973991d 100644 (file)
@@ -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);
 }