Skip to content

Commit c99f5cf

Browse files
committed
Reverted r87944 - issue #5109 should not have been backported
1 parent eb7047a commit c99f5cf

3 files changed

Lines changed: 5 additions & 29 deletions

File tree

Lib/test/test_array.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,6 @@ def test_tofromstring(self):
239239
if a.itemsize>1:
240240
self.assertRaises(ValueError, b.fromstring, "x")
241241

242-
def test_fromarray(self):
243-
a = array.array(self.typecode, self.example)
244-
b = array.array(self.typecode, a)
245-
self.assertEqual(a, b)
246-
247242
def test_repr(self):
248243
a = array.array(self.typecode, 2*self.example)
249244
self.assertEqual(a, eval(repr(a), {"array": array.array}))
@@ -963,11 +958,6 @@ def __getitem__(self, i):
963958

964959
self.assertRaises(AttributeError, setattr, a, "color", "blue")
965960

966-
def test_frombytearray(self):
967-
a = array.array('b', range(10))
968-
b = array.array(self.typecode, a)
969-
self.assertEqual(a, b)
970-
971961
class SignedNumberTest(NumberTest):
972962
example = [-1, 0, 1, 42, 0x7f]
973963
smallerexample = [-1, 0, 1, 42, 0x7e]

Misc/NEWS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,6 @@ Library
973973
Extension Modules
974974
-----------------
975975

976-
- Issue #5109: array.array constructor will now use fast code when
977-
initial data is provided in an array object with correct type.
978-
979976
- Issue #7384: If the system readline library is linked against ncurses,
980977
the curses module must be linked against ncurses as well. Otherwise it
981978
is not safe to load both the readline and curses modules in an application.

Modules/arraymodule.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,10 +1925,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
19251925

19261926
if (!(initial == NULL || PyList_Check(initial)
19271927
|| PyString_Check(initial) || PyTuple_Check(initial)
1928-
|| PyTuple_Check(initial)
1929-
|| ((c=='u') && PyUnicode_Check(initial))
1930-
|| (array_Check(initial)
1931-
&& c == ((arrayobject*)initial)->ob_descr->typecode))) {
1928+
|| (c == 'u' && PyUnicode_Check(initial)))) {
19321929
it = PyObject_GetIter(initial);
19331930
if (it == NULL)
19341931
return NULL;
@@ -1944,20 +1941,17 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
19441941
PyObject *a;
19451942
Py_ssize_t len;
19461943

1947-
if (initial == NULL)
1944+
if (initial == NULL || !(PyList_Check(initial)
1945+
|| PyTuple_Check(initial)))
19481946
len = 0;
1949-
else if (PyList_Check(initial))
1950-
len = PyList_GET_SIZE(initial);
1951-
else if (PyTuple_Check(initial) || array_Check(initial))
1952-
len = Py_SIZE(initial);
19531947
else
1954-
len = 0;
1948+
len = PySequence_Size(initial);
19551949

19561950
a = newarrayobject(type, len, descr);
19571951
if (a == NULL)
19581952
return NULL;
19591953

1960-
if (len > 0 && !array_Check(initial)) {
1954+
if (len > 0) {
19611955
Py_ssize_t i;
19621956
for (i = 0; i < len; i++) {
19631957
PyObject *v =
@@ -2007,11 +2001,6 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20072001
}
20082002
#endif
20092003
}
2010-
else if (initial != NULL && array_Check(initial)) {
2011-
arrayobject *self = (arrayobject *)a;
2012-
arrayobject *other = (arrayobject *)initial;
2013-
memcpy(self->ob_item, other->ob_item, len * other->ob_descr->itemsize);
2014-
}
20152004
if (it != NULL) {
20162005
if (array_iter_extend((arrayobject *)a, it) == -1) {
20172006
Py_DECREF(it);

0 commit comments

Comments
 (0)