Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Doc/library/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions Lib/test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,26 +426,6 @@ def test_tofromlist(self):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`array.array`: Remove ``tostring()`` and ``fromstring()`` methods.
They were aliases to ``tobytes()`` and ``frombytes()``, deprecated since
Python 3.2.
41 changes: 0 additions & 41 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
70 changes: 1 addition & 69 deletions Modules/clinic/arraymodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.