summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-04-24 10:41:55 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-04-24 10:41:55 (GMT)
commit84fc9aa6ce6a2113bc58db3f3a14e3d759177ab5 (patch)
tree03b823d8dd179eff42129f7de43940c7b9444487 /Modules/arraymodule.c
parentf4cf76dd5eabd8af5d2a866da1f75fa745aa6f29 (diff)
downloadcpython-84fc9aa6ce6a2113bc58db3f3a14e3d759177ab5.zip
cpython-84fc9aa6ce6a2113bc58db3f3a14e3d759177ab5.tar.gz
cpython-84fc9aa6ce6a2113bc58db3f3a14e3d759177ab5.tar.bz2
SF 686323: Minor array module enhancements
Allows use of tuples for the initializer.
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 204c8d3..c03160e 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1732,7 +1732,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
if (!(initial == NULL || PyList_Check(initial)
- || PyString_Check(initial)
+ || PyString_Check(initial) || PyTuple_Check(initial)
|| (c == 'u' && PyUnicode_Check(initial)))) {
PyErr_SetString(PyExc_TypeError,
"array initializer must be list or string");
@@ -1742,10 +1742,12 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (descr->typecode == c) {
PyObject *a;
int len;
- if (initial == NULL || !PyList_Check(initial))
+
+ if (initial == NULL || !(PyList_Check(initial)
+ || PyTuple_Check(initial)))
len = 0;
else
- len = PyList_Size(initial);
+ len = PySequence_Size(initial);
a = newarrayobject(type, len, descr);
if (a == NULL)
@@ -1755,7 +1757,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
int i;
for (i = 0; i < len; i++) {
PyObject *v =
- PyList_GetItem(initial, i);
+ PySequence_GetItem(initial, i);
if (setarrayitem(a, i, v) != 0) {
Py_DECREF(a);
return NULL;