Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76e5794

Browse files
committed
Merged revisions 83016 via svnmerge from
svn+ssh://[email protected]/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 ........
1 parent b034c75 commit 76e5794

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lib/json/tests/test_fail.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ def test_failures(self):
7474
pass
7575
else:
7676
self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc))
77+
78+
def test_non_string_keys_dict(self):
79+
data = {'a' : 1, (1, 2) : 2}
80+
81+
#This is for c encoder
82+
self.assertRaises(TypeError, json.dumps, data)
83+
84+
#This is for python encoder
85+
self.assertRaises(TypeError, json.dumps, data, indent=True)

Modules/_json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
14541454
}
14551455
else {
14561456
/* TODO: include repr of key */
1457-
PyErr_SetString(PyExc_ValueError, "keys must be a string");
1457+
PyErr_SetString(PyExc_TypeError, "keys must be a string");
14581458
goto bail;
14591459
}
14601460

0 commit comments

Comments
 (0)