From b51a57eb3233c99170c5f7c48daff822ab4c0fdf Mon Sep 17 00:00:00 2001
From: Georg Brandl <georg@python.org>
Date: Tue, 6 Mar 2007 13:32:52 +0000
Subject: Fix another reincarnation of bug #1576657 in defaultdict.

---
 Modules/_collectionsmodule.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index c37f9ac..c70019c 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -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);
-- 
cgit v0.12

