From 76e57947a10466654f09b696886eae5ff245e550 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 21 Jul 2010 12:35:38 +0000 Subject: [PATCH] Merged revisions 83016 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83016 | doug.hellmann | 2010-07-21 08:29:04 -0400 (Wed, 21 Jul 2010) | 1 line Apply patch from Ray Allen for issue 9296 ........ --- Lib/json/tests/test_fail.py | 9 +++++++++ Modules/_json.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/json/tests/test_fail.py b/Lib/json/tests/test_fail.py index 94e01e6918..9768edf19a 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 c96517686c..9a3708d090 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1454,7 +1454,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; } -- 2.40.0