summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2002-11-05 17:38:05 (GMT)
committerMichael W. Hudson <mwh@python.net>2002-11-05 17:38:05 (GMT)
commit5da854fe51ed76a236a44f82e6ee553a0ad9c51d (patch)
treee547e3e1a235ee2836d72ad712658691d601d7c9 /Objects
parentcc6cc5ddff06050e430d2d08a594ca8781bb7791 (diff)
downloadcpython-5da854fe51ed76a236a44f82e6ee553a0ad9c51d.zip
cpython-5da854fe51ed76a236a44f82e6ee553a0ad9c51d.tar.gz
cpython-5da854fe51ed76a236a44f82e6ee553a0ad9c51d.tar.bz2
This is Alex Martelli's patch
[ 633870 ] allow any seq assignment to a list slice plus a very silly little test case of my own.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/listobject.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 45b0951..c28bfb4 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -448,14 +448,22 @@ list_ass_slice(PyListObject *a, int ilow, int ihigh, PyObject *v)
list. :-( */
PyObject **recycle, **p;
PyObject **item;
+ PyObject *v_as_SF = NULL; /* PySequence_Fast(v) */
int n; /* Size of replacement list */
int d; /* Change in size */
int k; /* Loop index */
#define b ((PyListObject *)v)
if (v == NULL)
n = 0;
- else if (PyList_Check(v)) {
- n = b->ob_size;
+ else {
+ char msg[256];
+ sprintf(msg, "must assign sequence (not \"%.200s\") to slice",
+ v->ob_type->tp_name);
+ v_as_SF = PySequence_Fast(v, msg);
+ if(v_as_SF == NULL)
+ return -1;
+ n = PySequence_Fast_GET_SIZE(v_as_SF);
+
if (a == b) {
/* Special case "a[i:j] = a" -- copy b first */
int ret;
@@ -465,12 +473,6 @@ list_ass_slice(PyListObject *a, int ilow, int ihigh, PyObject *v)
return ret;
}
}
- else {
- PyErr_Format(PyExc_TypeError,
- "must assign list (not \"%.200s\") to slice",
- v->ob_type->tp_name);
- return -1;
- }
if (ilow < 0)
ilow = 0;
else if (ilow > a->ob_size)
@@ -512,7 +514,7 @@ list_ass_slice(PyListObject *a, int ilow, int ihigh, PyObject *v)
a->ob_size += d;
}
for (k = 0; k < n; k++, ilow++) {
- PyObject *w = b->ob_item[k];
+ PyObject *w = PySequence_Fast_GET_ITEM(v_as_SF, k);
Py_XINCREF(w);
item[ilow] = w;
}
@@ -525,6 +527,7 @@ list_ass_slice(PyListObject *a, int ilow, int ihigh, PyObject *v)
PyMem_FREE(a->ob_item);
a->ob_item = NULL;
}
+ Py_XDECREF(v_as_SF);
return 0;
#undef b
}