]> granicus.if.org Git - python/commitdiff
Use PyErr_WarnPy3k throughout
authorBenjamin Peterson <benjamin@python.org>
Sun, 27 Apr 2008 03:01:45 +0000 (03:01 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sun, 27 Apr 2008 03:01:45 +0000 (03:01 +0000)
14 files changed:
Modules/arraymodule.c
Objects/bufferobject.c
Objects/cellobject.c
Objects/codeobject.c
Objects/dictobject.c
Objects/exceptions.c
Objects/fileobject.c
Objects/listobject.c
Objects/methodobject.c
Objects/object.c
Objects/typeobject.c
Python/bltinmodule.c
Python/ceval.c
Python/sysmodule.c

index a77fd7d06452c10cb79d09b289fce9189ec5568b..a2b454a553dcad390901cdb88f415a4958691fee 100644 (file)
@@ -1257,10 +1257,8 @@ array.  Also called as read.");
 static PyObject *
 array_fromfile_as_read(arrayobject *self, PyObject *args)
 {
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning,
-                      "array.read() not supported in 3.x; "
-                      "use array.fromfile()") < 0)
+       if (PyErr_WarnPy3k("array.read() not supported in 3.x; "
+                      "use array.fromfile()", 1) < 0)
                return NULL;
        return array_fromfile(self, args);
 }
@@ -1298,10 +1296,8 @@ write.");
 static PyObject *
 array_tofile_as_write(arrayobject *self, PyObject *f)
 {
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning,
-                      "array.write() not supported in 3.x; "
-                      "use array.tofile()") < 0)
+       if (PyErr_WarnPy3k("array.write() not supported in 3.x; "
+                      "use array.tofile()", 1) < 0)
                return NULL;
        return array_tofile(self, f);
 }
index f4c69a0222b8d744f8d0179f38768a39656ee84b..37d9bcbb5a6ad7801b5c66b5a85a803a95b842c4 100644 (file)
@@ -233,9 +233,7 @@ buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
        Py_ssize_t offset = 0;
        Py_ssize_t size = Py_END_OF_BUFFER;
 
-       if (Py_Py3kWarningFlag &&
-           PyErr_WarnEx(PyExc_DeprecationWarning,
-                        "buffer() not supported in 3.x; "
+       if (PyErr_WarnPy3k("buffer() not supported in 3.x; "
                         "use memoryview()", 1) < 0)
                return NULL;
        
index 46955ab6e2ea635224f97a71ed17fe10c360ef75..e2a8d2969cda254fb80bee4fe37d0199357f5d50 100644 (file)
@@ -55,9 +55,8 @@ static int
 cell_compare(PyCellObject *a, PyCellObject *b)
 {
        /* Py3K warning for comparisons  */
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning,
-                      "cell comparisons not supported in 3.x") < 0) {
+       if (PyErr_WarnPy3k("cell comparisons not supported in 3.x",
+                           1) < 0) {
                return -2;
        }
 
index 33b4610c743b210eb1fe00e571e6cb50f3c02d6d..815135d534f85928e693613e07649505b6b9de0e 100644 (file)
@@ -340,10 +340,8 @@ code_richcompare(PyObject *self, PyObject *other, int op)
 
                /* Py3K warning if types are not equal and comparison
                    isn't == or !=  */
-               if (Py_Py3kWarningFlag &&
-                   PyErr_Warn(PyExc_DeprecationWarning,
-                              "code inequality comparisons not supported "
-                              "in 3.x") < 0) {
+               if (PyErr_WarnPy3k("code inequality comparisons not supported "
+                              "in 3.x", 1) < 0) {
                        return NULL;
                }
 
index d55209890dfe51f901d35c08296915309b795c69..2291524ac19c3ed2eaa142afbf4584286b568932 100644 (file)
@@ -1778,10 +1778,8 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
        }
        else {
                /* Py3K warning if comparison isn't == or !=  */
-               if (Py_Py3kWarningFlag &&
-                   PyErr_Warn(PyExc_DeprecationWarning,
-                              "dict inequality comparisons not supported "
-                              "in 3.x") < 0) {
+               if (PyErr_WarnPy3k("dict inequality comparisons not supported "
+                              "in 3.x", 1) < 0) {
                        return NULL;
                }
                res = Py_NotImplemented;
@@ -1811,10 +1809,8 @@ dict_contains(register PyDictObject *mp, PyObject *key)
 static PyObject *
 dict_has_key(register PyDictObject *mp, PyObject *key)
 {
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning, 
-                      "dict.has_key() not supported in 3.x; "
-                      "use the in operator") < 0)
+       if (PyErr_WarnPy3k("dict.has_key() not supported in 3.x; "
+                      "use the in operator", 1) < 0)
                return NULL;
        return dict_contains(mp, key);
 }
index 2451a911193d84818913564155d0e1fdbc91114c..4a9eba1e469b840d3238a6b83cd23d97faa956f0 100644 (file)
@@ -189,12 +189,9 @@ static PyMethodDef BaseException_methods[] = {
 static PyObject *
 BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
 {
-    if (Py_Py3kWarningFlag) {
-        if (PyErr_Warn(PyExc_DeprecationWarning,
-                       "__getitem__ not supported for exception "
-                       "classes in 3.x; use args attribute") == -1)
-            return NULL;
-    }
+    if (PyErr_WarnPy3k("__getitem__ not supported for exception "
+                       "classes in 3.x; use args attribute", 1) < 0)
+        return NULL;
     return PySequence_GetItem(self->args, index);
 }
 
@@ -202,12 +199,9 @@ static PyObject *
 BaseException_getslice(PyBaseExceptionObject *self,
                        Py_ssize_t start, Py_ssize_t stop)
 {
-    if (Py_Py3kWarningFlag) {
-        if (PyErr_Warn(PyExc_DeprecationWarning,
-                       "__getslice__ not supported for exception "
-                       "classes in 3.x; use args attribute") == -1)
-            return NULL;
-    }
+    if (PyErr_WarnPy3k("__getslice__ not supported for exception "
+                       "classes in 3.x; use args attribute", 1) < 0)
+        return NULL;
     return PySequence_GetSlice(self->args, start, stop);
 }
 
index d61e6a0bebea499469134f9c9d49912f48160a8b..ef0323256a392dcc5b9dbdad34473007f352e313 100644 (file)
@@ -1910,9 +1910,7 @@ get_newlines(PyFileObject *f, void *closure)
 static PyObject *
 get_softspace(PyFileObject *f, void *closure)
 {
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning,
-                      "file.softspace not supported in 3.x") < 0)
+       if (PyErr_WarnPy3k("file.softspace not supported in 3.x", 1) < 0)
                return NULL;
        return PyInt_FromLong(f->f_softspace);
 }
@@ -1921,9 +1919,7 @@ static int
 set_softspace(PyFileObject *f, PyObject *value)
 {
        int new;
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning,
-                      "file.softspace not supported in 3.x") < 0)
+       if (PyErr_WarnPy3k("file.softspace not supported in 3.x", 1) < 0)
                return -1;
 
        if (value == NULL) {
index 81617e44cb4523021e2978fa7117a1bbc50e9203..e4e8ae4d159fd23f8a8d58e7dbc41ecd9b181fec 100644 (file)
@@ -2038,9 +2038,7 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
        if (compare == Py_None)
                compare = NULL;
        if (compare != NULL && 
-            Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning, 
-                      "the cmp argument is not supported in 3.x") < 0)
+            PyErr_WarnPy3k("the cmp argument is not supported in 3.x", 1) < 0)
                return NULL;
        if (keyfunc == Py_None)
                keyfunc = NULL;
index e641df12fed96d2cda98e9f37879c23c379b3405..240cc05d468838bd6e2a1cfef3ef3e6eca7d99ea 100644 (file)
@@ -235,10 +235,8 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
            !PyCFunction_Check(other))
        {
                /* Py3K warning if types are not equal and comparison isn't == or !=  */
-               if (Py_Py3kWarningFlag &&
-                   PyErr_Warn(PyExc_DeprecationWarning,
-                              "builtin_function_or_method inequality "
-                              "comparisons not supported in 3.x") < 0) {
+               if (PyErr_WarnPy3k("builtin_function_or_method inequality "
+                              "comparisons not supported in 3.x", 1) < 0) {
                        return NULL;
                }
 
index e7d84adfb1ae7e178097596917d7b2faeb4fd5cc..f77f552826f49e89fd3a6e95173efcff301f2dd8 100644 (file)
@@ -868,9 +868,9 @@ try_3way_to_rich_compare(PyObject *v, PyObject *w, int op)
                /* Py3K warning if types are not equal and comparison isn't == or !=  */
                if (Py_Py3kWarningFlag &&
                    v->ob_type != w->ob_type && op != Py_EQ && op != Py_NE &&
-                   PyErr_Warn(PyExc_DeprecationWarning,
+                   PyErr_WarnEx(PyExc_DeprecationWarning,
                               "comparing unequal types not supported "
-                              "in 3.x") < 0) {
+                              "in 3.x", 1) < 0) {
                        return NULL;
                }
 
@@ -1691,9 +1691,9 @@ merge_list_attr(PyObject* dict, PyObject* obj, const char *attrname)
                if (Py_Py3kWarningFlag &&
                    (strcmp(attrname, "__members__") == 0 ||
                     strcmp(attrname, "__methods__") == 0)) {
-                       if (PyErr_Warn(PyExc_DeprecationWarning, 
+                       if (PyErr_WarnEx(PyExc_DeprecationWarning, 
                                       "__members__ and __methods__ not "
-                                      "supported in 3.x") < 0) {
+                                      "supported in 3.x", 1) < 0) {
                                Py_XDECREF(list);
                                return -1;
                        }
index 6b732dd7669cce9de6fad23db78ea6231dd51bac..54ad714ec80f2f9bf7c93a00fb944f0cd6978954 100644 (file)
@@ -608,9 +608,9 @@ type_richcompare(PyObject *v, PyObject *w, int op)
 
        /* Py3K warning if comparison isn't == or !=  */
        if (Py_Py3kWarningFlag && op != Py_EQ && op != Py_NE &&
-               PyErr_Warn(PyExc_DeprecationWarning,
+               PyErr_WarnEx(PyExc_DeprecationWarning,
                           "type inequality comparisons not supported "
-                          "in 3.x") < 0) {
+                          "in 3.x", 1) < 0) {
                return NULL;
        }
 
index bcdcda6355894c8e2483723166ae0720186639e0..5d191a63e01fd60fef806f9d3c01a45f50bdd753 100644 (file)
@@ -165,10 +165,8 @@ builtin_apply(PyObject *self, PyObject *args)
        PyObject *func, *alist = NULL, *kwdict = NULL;
        PyObject *t = NULL, *retval = NULL;
 
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning, 
-                      "apply() not supported in 3.x; "
-                      "use func(*args, **kwargs)") < 0)
+       if (PyErr_WarnPy3k("apply() not supported in 3.x; "
+                      "use func(*args, **kwargs)", 1) < 0)
                return NULL;
 
        if (!PyArg_UnpackTuple(args, "apply", 1, 3, &func, &alist, &kwdict))
@@ -225,10 +223,8 @@ Return the binary representation of an integer or long integer.");
 static PyObject *
 builtin_callable(PyObject *self, PyObject *v)
 {
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning, 
-                      "callable() not supported in 3.x; "
-                      "use hasattr(o, '__call__')") < 0)
+       if (PyErr_WarnPy3k("callable() not supported in 3.x; "
+                      "use hasattr(o, '__call__')", 1) < 0)
                return NULL;
        return PyBool_FromLong((long)PyCallable_Check(v));
 }
@@ -438,9 +434,7 @@ builtin_coerce(PyObject *self, PyObject *args)
        PyObject *v, *w;
        PyObject *res;
 
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning, 
-                      "coerce() not supported in 3.x") < 0)
+       if (PyErr_WarnPy3k("coerce() not supported in 3.x", 1) < 0)
                return NULL;
 
        if (!PyArg_UnpackTuple(args, "coerce", 2, 2, &v, &w))
@@ -709,9 +703,8 @@ builtin_execfile(PyObject *self, PyObject *args)
        PyCompilerFlags cf;
        int exists;
 
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning, 
-                      "execfile() not supported in 3.x; use exec()") < 0)
+       if (PyErr_WarnPy3k("execfile() not supported in 3.x; use exec()",
+                           1) < 0)
                return NULL;
 
        if (!PyArg_ParseTuple(args, "s|O!O:execfile",
@@ -937,10 +930,8 @@ builtin_map(PyObject *self, PyObject *args)
        n--;
 
        if (func == Py_None) {
-               if (Py_Py3kWarningFlag &&
-                   PyErr_Warn(PyExc_DeprecationWarning, 
-                              "map(None, ...) not supported in 3.x; "
-                              "use list(...)") < 0)
+               if (PyErr_WarnPy3k("map(None, ...) not supported in 3.x; "
+                              "use list(...)", 1) < 0)
                        return NULL;
                if (n == 1) {
                        /* map(None, S) is the same as list(S). */
@@ -1967,10 +1958,8 @@ builtin_reduce(PyObject *self, PyObject *args)
 {
        PyObject *seq, *func, *result = NULL, *it;
 
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning, 
-                      "reduce() not supported in 3.x; "
-                      "use functools.reduce()") < 0)
+       if (PyErr_WarnPy3k("reduce() not supported in 3.x; "
+                      "use functools.reduce()", 1) < 0)
                return NULL;
 
        if (!PyArg_UnpackTuple(args, "reduce", 2, 3, &func, &seq, &result))
@@ -2045,9 +2034,8 @@ sequence is empty.");
 static PyObject *
 builtin_reload(PyObject *self, PyObject *v)
 {
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning, 
-                      "reload() not supported in 3.x; use imp.reload()") < 0)
+       if (PyErr_WarnPy3k("In 3.x, reload() is renamed to imp.reload()",
+                           1) < 0)
                return NULL;
 
        return PyImport_ReloadModule(v);
index 7c7116ce41a7a396242c706841e50f6ed705d6fd..c08585178c89522ad8ccaa36488eebadc6af01bb 100644 (file)
@@ -3164,9 +3164,9 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
 
        assert(PyExceptionClass_Check(type));
        if (Py_Py3kWarningFlag && PyClass_Check(type)) {
-               if (PyErr_Warn(PyExc_DeprecationWarning,
+               if (PyErr_WarnEx(PyExc_DeprecationWarning,
                               "exceptions must derive from BaseException "
-                              "in 3.x") == -1)
+                              "in 3.x", 1) == -1)
                        goto raise_error;
        }
 
index 8c82d45d379e7f2a75ce4bf28737acd657c6f625..83d7d68bb2ee3f7d15a6083c4ae6b1c24f1eb196 100644 (file)
@@ -172,10 +172,8 @@ sys_exc_clear(PyObject *self, PyObject *noargs)
        PyThreadState *tstate;
        PyObject *tmp_type, *tmp_value, *tmp_tb;
 
-       if (Py_Py3kWarningFlag &&
-           PyErr_Warn(PyExc_DeprecationWarning,
-                      "sys.exc_clear() not supported in 3.x; "
-                      "use except clauses") < 0)
+       if (PyErr_WarnPy3k("sys.exc_clear() not supported in 3.x; "
+                      "use except clauses", 1) < 0)
                return NULL;
 
        tstate = PyThreadState_GET();