]> granicus.if.org Git - python/commitdiff
Fix another reincarnation of bug #1576657 in defaultdict.
authorGeorg Brandl <georg@python.org>
Tue, 6 Mar 2007 13:32:52 +0000 (13:32 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 6 Mar 2007 13:32:52 +0000 (13:32 +0000)
Modules/_collectionsmodule.c

index c37f9ace157479bcd55358deff06eb0fa378bcdd..c70019cc402402df5055e739459994436f12e5a1 100644 (file)
@@ -1075,7 +1075,7 @@ static PyTypeObject defdict_type; /* Forward */
 
 PyDoc_STRVAR(defdict_missing_doc,
 "__missing__(key) # Called by __getitem__ for missing key; pseudo-code:\n\
-  if self.default_factory is None: raise KeyError(key)\n\
+  if self.default_factory is None: raise KeyError((key,))\n\
   self[key] = value = self.default_factory()\n\
   return value\n\
 ");
@@ -1087,7 +1087,11 @@ defdict_missing(defdictobject *dd, PyObject *key)
        PyObject *value;
        if (factory == NULL || factory == Py_None) {
                /* XXX Call dict.__missing__(key) */
-               PyErr_SetObject(PyExc_KeyError, key);
+               PyObject *tup;
+               tup = PyTuple_Pack(1, key);
+               if (!tup) return NULL;
+               PyErr_SetObject(PyExc_KeyError, tup);
+               Py_DECREF(tup);
                return NULL;
        }
        value = PyEval_CallObject(factory, NULL);