summaryrefslogtreecommitdiff
path: root/Lib/json/encoder.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-25 17:38:20 +0200
committerGitHub <noreply@github.com>2017-11-25 17:38:20 +0200
commitcfa797c0681b7fef47cf93955fd06b54ddd09a7f (patch)
tree6e4ecf5ed329d339b26f1eb2bf1f73950abbee72 /Lib/json/encoder.py
parent5b48dc638b7405fd9bde4d854bf477dfeaaddf44 (diff)
downloadcpython-git-cfa797c0681b7fef47cf93955fd06b54ddd09a7f.tar.gz
bpo-24641: Improved error message for JSON unserializible keys. (#4364)
Also updated an example for default() in the module docstring. Removed quotes around type name in other error messages.
Diffstat (limited to 'Lib/json/encoder.py')
-rw-r--r--Lib/json/encoder.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index 41a497c5da..fb083ed61b 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -176,8 +176,8 @@ class JSONEncoder(object):
return JSONEncoder.default(self, o)
"""
- raise TypeError("Object of type '%s' is not JSON serializable" %
- o.__class__.__name__)
+ raise TypeError(f'Object of type {o.__class__.__name__} '
+ f'is not JSON serializable')
def encode(self, o):
"""Return a JSON string representation of a Python data structure.
@@ -373,7 +373,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
elif _skipkeys:
continue
else:
- raise TypeError("key " + repr(key) + " is not a string")
+ raise TypeError(f'keys must be str, int, float, bool or None, '
+ f'not {key.__class__.__name__}')
if first:
first = False
else: