Skip to content

Commit 84fc9aa

Browse files
committed
SF 686323: Minor array module enhancements
Allows use of tuples for the initializer.
1 parent f4cf76d commit 84fc9aa

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Modules/arraymodule.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
17321732
return NULL;
17331733

17341734
if (!(initial == NULL || PyList_Check(initial)
1735-
|| PyString_Check(initial)
1735+
|| PyString_Check(initial) || PyTuple_Check(initial)
17361736
|| (c == 'u' && PyUnicode_Check(initial)))) {
17371737
PyErr_SetString(PyExc_TypeError,
17381738
"array initializer must be list or string");
@@ -1742,10 +1742,12 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
17421742
if (descr->typecode == c) {
17431743
PyObject *a;
17441744
int len;
1745-
if (initial == NULL || !PyList_Check(initial))
1745+
1746+
if (initial == NULL || !(PyList_Check(initial)
1747+
|| PyTuple_Check(initial)))
17461748
len = 0;
17471749
else
1748-
len = PyList_Size(initial);
1750+
len = PySequence_Size(initial);
17491751

17501752
a = newarrayobject(type, len, descr);
17511753
if (a == NULL)
@@ -1755,7 +1757,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
17551757
int i;
17561758
for (i = 0; i < len; i++) {
17571759
PyObject *v =
1758-
PyList_GetItem(initial, i);
1760+
PySequence_GetItem(initial, i);
17591761
if (setarrayitem(a, i, v) != 0) {
17601762
Py_DECREF(a);
17611763
return NULL;

0 commit comments

Comments
 (0)