Skip to content

Commit 0131aba

Browse files
authored
bpo-38916: array.array: remove fromstring() and tostring() (GH-17487)
array.array: Remove tostring() and fromstring() methods. They were aliases to tobytes() and frombytes(), deprecated since Python 3.2.
1 parent a1838ec commit 0131aba

File tree

6 files changed

+9
-140
lines changed

6 files changed

+9
-140
lines changed

Doc/library/array.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ The following data items and methods are also supported:
169169
a.append(x)`` except that if there is a type error, the array is unchanged.
170170

171171

172-
.. method:: array.fromstring()
173-
174-
Deprecated alias for :meth:`frombytes`.
175-
176-
177172
.. method:: array.fromunicode(s)
178173

179174
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:
231226
Convert the array to an ordinary list with the same items.
232227

233228

234-
.. method:: array.tostring()
235-
236-
Deprecated alias for :meth:`tobytes`.
237-
238-
239229
.. method:: array.tounicode()
240230

241231
Convert the array to a unicode string. The array must be a type ``'u'`` array;

Doc/whatsnew/3.9.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ Deprecated
279279
Removed
280280
=======
281281

282+
* :class:`array.array`: ``tostring()`` and ``fromstring()`` methods have been
283+
removed. They were aliases to ``tobytes()`` and ``frombytes()``, deprecated
284+
since Python 3.2.
285+
(Contributed by Victor Stinner in :issue:`38916`.)
286+
282287
* The abstract base classes in :mod:`collections.abc` no longer are
283288
exposed in the regular :mod:`collections` module. This will help
284289
create a clearer distinction between the concrete classes and the abstract

Lib/test/test_array.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -426,26 +426,6 @@ def test_tofromlist(self):
426426
b.fromlist(a.tolist())
427427
self.assertEqual(a, b)
428428

429-
def test_tofromstring(self):
430-
# Warnings not raised when arguments are incorrect as Argument Clinic
431-
# handles that before the warning can be raised.
432-
nb_warnings = 2
433-
with warnings.catch_warnings(record=True) as r:
434-
warnings.filterwarnings("always",
435-
message=r"(to|from)string\(\) is deprecated",
436-
category=DeprecationWarning)
437-
a = array.array(self.typecode, 2*self.example)
438-
b = array.array(self.typecode)
439-
self.assertRaises(TypeError, a.tostring, 42)
440-
self.assertRaises(TypeError, b.fromstring)
441-
self.assertRaises(TypeError, b.fromstring, 42)
442-
b.fromstring(a.tostring())
443-
self.assertEqual(a, b)
444-
if a.itemsize>1:
445-
self.assertRaises(ValueError, b.fromstring, "x")
446-
nb_warnings += 1
447-
self.assertEqual(len(r), nb_warnings)
448-
449429
def test_tofrombytes(self):
450430
a = array.array(self.typecode, 2*self.example)
451431
b = array.array(self.typecode)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:class:`array.array`: Remove ``tostring()`` and ``fromstring()`` methods.
2+
They were aliases to ``tobytes()`` and ``frombytes()``, deprecated since
3+
Python 3.2.

Modules/arraymodule.c

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,27 +1623,6 @@ frombytes(arrayobject *self, Py_buffer *buffer)
16231623
Py_RETURN_NONE;
16241624
}
16251625

1626-
/*[clinic input]
1627-
array.array.fromstring
1628-
1629-
buffer: Py_buffer(accept={str, buffer})
1630-
/
1631-
1632-
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).
1633-
1634-
This method is deprecated. Use frombytes instead.
1635-
[clinic start generated code]*/
1636-
1637-
static PyObject *
1638-
array_array_fromstring_impl(arrayobject *self, Py_buffer *buffer)
1639-
/*[clinic end generated code: output=31c4baa779df84ce input=a3341a512e11d773]*/
1640-
{
1641-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
1642-
"fromstring() is deprecated. Use frombytes() instead.", 2) != 0)
1643-
return NULL;
1644-
return frombytes(self, buffer);
1645-
}
1646-
16471626
/*[clinic input]
16481627
array.array.frombytes
16491628
@@ -1678,24 +1657,6 @@ array_array_tobytes_impl(arrayobject *self)
16781657
}
16791658
}
16801659

1681-
/*[clinic input]
1682-
array.array.tostring
1683-
1684-
Convert the array to an array of machine values and return the bytes representation.
1685-
1686-
This method is deprecated. Use tobytes instead.
1687-
[clinic start generated code]*/
1688-
1689-
static PyObject *
1690-
array_array_tostring_impl(arrayobject *self)
1691-
/*[clinic end generated code: output=7d6bd92745a2c8f3 input=b6c0ddee7b30457e]*/
1692-
{
1693-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
1694-
"tostring() is deprecated. Use tobytes() instead.", 2) != 0)
1695-
return NULL;
1696-
return array_array_tobytes_impl(self);
1697-
}
1698-
16991660
/*[clinic input]
17001661
array.array.fromunicode
17011662
@@ -2283,7 +2244,6 @@ static PyMethodDef array_methods[] = {
22832244
ARRAY_ARRAY_EXTEND_METHODDEF
22842245
ARRAY_ARRAY_FROMFILE_METHODDEF
22852246
ARRAY_ARRAY_FROMLIST_METHODDEF
2286-
ARRAY_ARRAY_FROMSTRING_METHODDEF
22872247
ARRAY_ARRAY_FROMBYTES_METHODDEF
22882248
ARRAY_ARRAY_FROMUNICODE_METHODDEF
22892249
ARRAY_ARRAY_INDEX_METHODDEF
@@ -2294,7 +2254,6 @@ static PyMethodDef array_methods[] = {
22942254
ARRAY_ARRAY_REVERSE_METHODDEF
22952255
ARRAY_ARRAY_TOFILE_METHODDEF
22962256
ARRAY_ARRAY_TOLIST_METHODDEF
2297-
ARRAY_ARRAY_TOSTRING_METHODDEF
22982257
ARRAY_ARRAY_TOBYTES_METHODDEF
22992258
ARRAY_ARRAY_TOUNICODE_METHODDEF
23002259
ARRAY_ARRAY___SIZEOF___METHODDEF

Modules/clinic/arraymodule.c.h

Lines changed: 1 addition & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)