Index: Objects/abstract.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/abstract.c,v retrieving revision 2.139 diff -u -p -r2.139 abstract.c --- Objects/abstract.c 24 Sep 2005 21:23:05 -0000 2.139 +++ Objects/abstract.c 28 Sep 2005 12:17:24 -0000 @@ -1277,6 +1277,7 @@ int PySequence_SetItem(PyObject *s, int i, PyObject *o) { PySequenceMethods *m; + PyObject *item; if (s == NULL) { null_error(); @@ -1295,6 +1296,19 @@ PySequence_SetItem(PyObject *s, int i, P } return m->sq_ass_item(s, i, o); } + + /* before erroring out, check if the item we want to assign + * is already at the specified index; this makes it possible + * to use inplace operators on mutable types inside immutable + * containers */ + + item = PySequence_GetItem(s, i); + if (item && item == o) { + Py_DECREF(item); + return 0; + } + Py_XDECREF(item); + type_error("object does not support item assignment"); return -1;