]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38916: array.array: remove fromstring() and tostring() (GH-17487)
authorVictor Stinner <vstinner@python.org>
Mon, 9 Dec 2019 13:09:14 +0000 (14:09 +0100)
committerGitHub <noreply@github.com>
Mon, 9 Dec 2019 13:09:14 +0000 (14:09 +0100)
array.array: Remove tostring() and fromstring() methods.  They were
aliases to tobytes() and frombytes(), deprecated since Python 3.2.

Doc/library/array.rst
Doc/whatsnew/3.9.rst
Lib/test/test_array.py
Misc/NEWS.d/next/Library/2019-12-06-18-47-56.bpo-38916.K-raU8.rst [new file with mode: 0644]
Modules/arraymodule.c
Modules/clinic/arraymodule.c.h

index 2ae2a071262a17275119b9495be0efc82577e5df..c9a9b1dabb2a792893c3c4a2dfc8c43ad36c94bd 100644 (file)
@@ -169,11 +169,6 @@ The following data items and methods are also supported:
    a.append(x)`` except that if there is a type error, the array is unchanged.
 
 
-.. method:: array.fromstring()
-
-   Deprecated alias for :meth:`frombytes`.
-
-
 .. method:: array.fromunicode(s)
 
    Extends this array with data from the given unicode string.  The array must
@@ -231,11 +226,6 @@ The following data items and methods are also supported:
    Convert the array to an ordinary list with the same items.
 
 
-.. method:: array.tostring()
-
-   Deprecated alias for :meth:`tobytes`.
-
-
 .. method:: array.tounicode()
 
    Convert the array to a unicode string.  The array must be a type ``'u'`` array;
index 1cd96ef3b07af30c82e5ccb468ffa03b12c4067d..7cf49bfbb93f94bb72542e7892821b3f5201917f 100644 (file)
@@ -279,6 +279,11 @@ Deprecated
 Removed
 =======
 
+* :class:`array.array`: ``tostring()`` and ``fromstring()`` methods have been
+  removed. They were aliases to ``tobytes()`` and ``frombytes()``, deprecated
+  since Python 3.2.
+  (Contributed by Victor Stinner in :issue:`38916`.)
+
 * The abstract base classes in :mod:`collections.abc` no longer are
   exposed in the regular :mod:`collections` module.  This will help
   create a clearer distinction between the concrete classes and the abstract
index c2439579e8ee5b456cd13b628e330b2d56749a90..5f612fba8a497c2d76d4b5d49dadf7747bf12c40 100644 (file)
@@ -426,26 +426,6 @@ class BaseTest:
         b.fromlist(a.tolist())
         self.assertEqual(a, b)
 
-    def test_tofromstring(self):
-        # Warnings not raised when arguments are incorrect as Argument Clinic
-        # handles that before the warning can be raised.
-        nb_warnings = 2
-        with warnings.catch_warnings(record=True) as r:
-            warnings.filterwarnings("always",
-                                    message=r"(to|from)string\(\) is deprecated",
-                                    category=DeprecationWarning)
-            a = array.array(self.typecode, 2*self.example)
-            b = array.array(self.typecode)
-            self.assertRaises(TypeError, a.tostring, 42)
-            self.assertRaises(TypeError, b.fromstring)
-            self.assertRaises(TypeError, b.fromstring, 42)
-            b.fromstring(a.tostring())
-            self.assertEqual(a, b)
-            if a.itemsize>1:
-                self.assertRaises(ValueError, b.fromstring, "x")
-                nb_warnings += 1
-        self.assertEqual(len(r), nb_warnings)
-
     def test_tofrombytes(self):
         a = array.array(self.typecode, 2*self.example)
         b = array.array(self.typecode)
diff --git a/Misc/NEWS.d/next/Library/2019-12-06-18-47-56.bpo-38916.K-raU8.rst b/Misc/NEWS.d/next/Library/2019-12-06-18-47-56.bpo-38916.K-raU8.rst
new file mode 100644 (file)
index 0000000..cb4c4c0
--- /dev/null
@@ -0,0 +1,3 @@
+:class:`array.array`: Remove ``tostring()`` and ``fromstring()`` methods.
+They were aliases to ``tobytes()`` and ``frombytes()``, deprecated since
+Python 3.2.
index 1ceba9e63cbdf434d99a619765de300e4d262d6e..edb56ab6e18736932c418a8d3ed2ba542b4b1155 100644 (file)
@@ -1623,27 +1623,6 @@ frombytes(arrayobject *self, Py_buffer *buffer)
     Py_RETURN_NONE;
 }
 
-/*[clinic input]
-array.array.fromstring
-
-    buffer: Py_buffer(accept={str, buffer})
-    /
-
-Appends items from the string, interpreting it as an array of machine values, as if it had been read from a file using the fromfile() method).
-
-This method is deprecated. Use frombytes instead.
-[clinic start generated code]*/
-
-static PyObject *
-array_array_fromstring_impl(arrayobject *self, Py_buffer *buffer)
-/*[clinic end generated code: output=31c4baa779df84ce input=a3341a512e11d773]*/
-{
-    if (PyErr_WarnEx(PyExc_DeprecationWarning,
-            "fromstring() is deprecated. Use frombytes() instead.", 2) != 0)
-        return NULL;
-    return frombytes(self, buffer);
-}
-
 /*[clinic input]
 array.array.frombytes
 
@@ -1678,24 +1657,6 @@ array_array_tobytes_impl(arrayobject *self)
     }
 }
 
-/*[clinic input]
-array.array.tostring
-
-Convert the array to an array of machine values and return the bytes representation.
-
-This method is deprecated. Use tobytes instead.
-[clinic start generated code]*/
-
-static PyObject *
-array_array_tostring_impl(arrayobject *self)
-/*[clinic end generated code: output=7d6bd92745a2c8f3 input=b6c0ddee7b30457e]*/
-{
-    if (PyErr_WarnEx(PyExc_DeprecationWarning,
-            "tostring() is deprecated. Use tobytes() instead.", 2) != 0)
-        return NULL;
-    return array_array_tobytes_impl(self);
-}
-
 /*[clinic input]
 array.array.fromunicode
 
@@ -2283,7 +2244,6 @@ static PyMethodDef array_methods[] = {
     ARRAY_ARRAY_EXTEND_METHODDEF
     ARRAY_ARRAY_FROMFILE_METHODDEF
     ARRAY_ARRAY_FROMLIST_METHODDEF
-    ARRAY_ARRAY_FROMSTRING_METHODDEF
     ARRAY_ARRAY_FROMBYTES_METHODDEF
     ARRAY_ARRAY_FROMUNICODE_METHODDEF
     ARRAY_ARRAY_INDEX_METHODDEF
@@ -2294,7 +2254,6 @@ static PyMethodDef array_methods[] = {
     ARRAY_ARRAY_REVERSE_METHODDEF
     ARRAY_ARRAY_TOFILE_METHODDEF
     ARRAY_ARRAY_TOLIST_METHODDEF
-    ARRAY_ARRAY_TOSTRING_METHODDEF
     ARRAY_ARRAY_TOBYTES_METHODDEF
     ARRAY_ARRAY_TOUNICODE_METHODDEF
     ARRAY_ARRAY___SIZEOF___METHODDEF
index 33f82d4da8b6c90cf34ff5fd1bd2d9fbb90804af..e1f4b0397b9cb5b9a3cc1f45ff3516fc281b6bef 100644 (file)
@@ -312,54 +312,6 @@ array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored))
     return array_array_tolist_impl(self);
 }
 
-PyDoc_STRVAR(array_array_fromstring__doc__,
-"fromstring($self, buffer, /)\n"
-"--\n"
-"\n"
-"Appends items from the string, interpreting it as an array of machine values, as if it had been read from a file using the fromfile() method).\n"
-"\n"
-"This method is deprecated. Use frombytes instead.");
-
-#define ARRAY_ARRAY_FROMSTRING_METHODDEF    \
-    {"fromstring", (PyCFunction)array_array_fromstring, METH_O, array_array_fromstring__doc__},
-
-static PyObject *
-array_array_fromstring_impl(arrayobject *self, Py_buffer *buffer);
-
-static PyObject *
-array_array_fromstring(arrayobject *self, PyObject *arg)
-{
-    PyObject *return_value = NULL;
-    Py_buffer buffer = {NULL, NULL};
-
-    if (PyUnicode_Check(arg)) {
-        Py_ssize_t len;
-        const char *ptr = PyUnicode_AsUTF8AndSize(arg, &len);
-        if (ptr == NULL) {
-            goto exit;
-        }
-        PyBuffer_FillInfo(&buffer, arg, (void *)ptr, len, 1, 0);
-    }
-    else { /* any bytes-like object */
-        if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
-            goto exit;
-        }
-        if (!PyBuffer_IsContiguous(&buffer, 'C')) {
-            _PyArg_BadArgument("fromstring", "argument", "contiguous buffer", arg);
-            goto exit;
-        }
-    }
-    return_value = array_array_fromstring_impl(self, &buffer);
-
-exit:
-    /* Cleanup for buffer */
-    if (buffer.obj) {
-       PyBuffer_Release(&buffer);
-    }
-
-    return return_value;
-}
-
 PyDoc_STRVAR(array_array_frombytes__doc__,
 "frombytes($self, buffer, /)\n"
 "--\n"
@@ -414,26 +366,6 @@ array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored))
     return array_array_tobytes_impl(self);
 }
 
-PyDoc_STRVAR(array_array_tostring__doc__,
-"tostring($self, /)\n"
-"--\n"
-"\n"
-"Convert the array to an array of machine values and return the bytes representation.\n"
-"\n"
-"This method is deprecated. Use tobytes instead.");
-
-#define ARRAY_ARRAY_TOSTRING_METHODDEF    \
-    {"tostring", (PyCFunction)array_array_tostring, METH_NOARGS, array_array_tostring__doc__},
-
-static PyObject *
-array_array_tostring_impl(arrayobject *self);
-
-static PyObject *
-array_array_tostring(arrayobject *self, PyObject *Py_UNUSED(ignored))
-{
-    return array_array_tostring_impl(self);
-}
-
 PyDoc_STRVAR(array_array_fromunicode__doc__,
 "fromunicode($self, ustr, /)\n"
 "--\n"
@@ -599,4 +531,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
 
 #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF    \
     {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
-/*[clinic end generated code: output=6aa421571e2c0756 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f649fc0bc9f6b13a input=a9049054013a1b77]*/