]> granicus.if.org Git - python/commitdiff
#2359: add Py3k warning for array.read/array.write.
authorGeorg Brandl <georg@python.org>
Tue, 25 Mar 2008 08:37:23 +0000 (08:37 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 25 Mar 2008 08:37:23 +0000 (08:37 +0000)
Misc/NEWS
Modules/arraymodule.c

index 881cc83a51b0b9206b9536754d7333cb1b0035b4..4afd6cad10bb85dfcc1c2b7be3300ff2f66f9034 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,8 @@ Core and builtins
   are still valid. There are binary literals with a prefix of "0b".
   This also affects int(x, 0).
 
+- Issue #2359: Adding deprecation warnings for array.{read,write}.
+
 - Issue #1779871: Gnu gcc can now build Python on OS X because the
   flags -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd are no
   longer passed.
index 56556442a702fede3f0eb8b4a4eed3ceaddc0e7d..a77fd7d06452c10cb79d09b289fce9189ec5568b 100644 (file)
@@ -1254,6 +1254,18 @@ Read n objects from the file object f and append them to the end of the\n\
 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)
+               return NULL;
+       return array_fromfile(self, args);
+}
+
+
 static PyObject *
 array_tofile(arrayobject *self, PyObject *f)
 {
@@ -1283,6 +1295,18 @@ Write all items (as machine values) to the file object f.  Also called as\n\
 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)
+               return NULL;
+       return array_tofile(self, f);
+}
+
+
 static PyObject *
 array_fromlist(arrayobject *self, PyObject *list)
 {
@@ -1522,7 +1546,7 @@ PyMethodDef array_methods[] = {
         insert_doc},
        {"pop",         (PyCFunction)array_pop,         METH_VARARGS,
         pop_doc},
-       {"read",        (PyCFunction)array_fromfile,    METH_VARARGS,
+       {"read",        (PyCFunction)array_fromfile_as_read,    METH_VARARGS,
         fromfile_doc},
        {"__reduce__",  (PyCFunction)array_reduce,      METH_NOARGS,
         array_doc},
@@ -1542,7 +1566,7 @@ PyMethodDef array_methods[] = {
        {"tounicode",   (PyCFunction)array_tounicode,   METH_NOARGS,
         tounicode_doc},
 #endif
-       {"write",       (PyCFunction)array_tofile     METH_O,
+       {"write",       (PyCFunction)array_tofile_as_write,     METH_O,
         tofile_doc},
        {NULL,          NULL}           /* sentinel */
 };