From: Doug Hellmann Date: Wed, 21 Jul 2010 12:36:33 +0000 (+0000) Subject: Apply patch from Ray Allen for issue 9296 X-Git-Tag: v2.7.1rc1~577 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f31db93fc1239a6d9c2fe61c73ba9303005208e1;p=python Apply patch from Ray Allen for issue 9296 --- diff --git a/Lib/json/tests/test_fail.py b/Lib/json/tests/test_fail.py index 72df517d14..dd9ec4137e 100644 --- a/Lib/json/tests/test_fail.py +++ b/Lib/json/tests/test_fail.py @@ -74,3 +74,12 @@ class TestFail(TestCase): pass else: self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc)) + + def test_non_string_keys_dict(self): + data = {'a' : 1, (1, 2) : 2} + + #This is for c encoder + self.assertRaises(TypeError, json.dumps, data) + + #This is for python encoder + self.assertRaises(TypeError, json.dumps, data, indent=True) diff --git a/Modules/_json.c b/Modules/_json.c index b6599f83dc..2ef66e3fa4 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -2147,7 +2147,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss } else { /* TODO: include repr of key */ - PyErr_SetString(PyExc_ValueError, "keys must be a string"); + PyErr_SetString(PyExc_TypeError, "keys must be a string"); goto bail; }