]> granicus.if.org Git - python/commitdiff
Apply patch from Ray Allen for issue 9296
authorDoug Hellmann <doug.hellmann@gmail.com>
Wed, 21 Jul 2010 12:36:33 +0000 (12:36 +0000)
committerDoug Hellmann <doug.hellmann@gmail.com>
Wed, 21 Jul 2010 12:36:33 +0000 (12:36 +0000)
Lib/json/tests/test_fail.py
Modules/_json.c

index 72df517d14adb9b1d46f6446122737030b5b518e..dd9ec4137ea4cdfd20a56d882070b232dd6492e2 100644 (file)
@@ -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)
index b6599f83dc78c6e9315c84eaf3e443bf556edaa5..2ef66e3fa4ee943407dea4f30957e347d7dc3aee 100644 (file)
@@ -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;
         }