]> granicus.if.org Git - python/commitdiff
SF 686323: Minor array module enhancements
authorRaymond Hettinger <python@rcn.com>
Thu, 24 Apr 2003 10:41:55 +0000 (10:41 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 24 Apr 2003 10:41:55 +0000 (10:41 +0000)
Allows use of tuples for the initializer.

Modules/arraymodule.c

index 204c8d3c5f3b0691899d70becb214393e0523660..c03160eabac4b0c7f5c168bd32e456e02978330d 100644 (file)
@@ -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;