]> 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:29:04 +0000 (12:29 +0000)
committerDoug Hellmann <doug.hellmann@gmail.com>
Wed, 21 Jul 2010 12:29:04 +0000 (12:29 +0000)
Lib/json/tests/test_fail.py
Modules/_json.c

index 94e01e69181b53067c377246289199346e5f7fa2..9768edf19a89b3f4e619844e2df7ef45b7eeff81 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 c96517686c0b1cd2cc9ce48bdf77a00896f93b18..9a3708d090c2ad74506a5f1ffae8d0abb32dd025 100644 (file)
@@ -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;
         }