summaryrefslogtreecommitdiffstats
path: root/Lib/json/__init__.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-25 15:38:20 (GMT)
committerGitHub <noreply@github.com>2017-11-25 15:38:20 (GMT)
commitcfa797c0681b7fef47cf93955fd06b54ddd09a7f (patch)
tree6e4ecf5ed329d339b26f1eb2bf1f73950abbee72 /Lib/json/__init__.py
parent5b48dc638b7405fd9bde4d854bf477dfeaaddf44 (diff)
downloadcpython-cfa797c0681b7fef47cf93955fd06b54ddd09a7f.zip
cpython-cfa797c0681b7fef47cf93955fd06b54ddd09a7f.tar.gz
cpython-cfa797c0681b7fef47cf93955fd06b54ddd09a7f.tar.bz2
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/__init__.py')
-rw-r--r--Lib/json/__init__.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py
index 6d0511e..a566009 100644
--- a/Lib/json/__init__.py
+++ b/Lib/json/__init__.py
@@ -76,7 +76,8 @@ Specializing JSON object encoding::
>>> def encode_complex(obj):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
- ... raise TypeError(repr(obj) + " is not JSON serializable")
+ ... raise TypeError(f'Object of type {obj.__class__.__name__} '
+ ... f'is not JSON serializable')
...
>>> json.dumps(2 + 1j, default=encode_complex)
'[2.0, 1.0]'
@@ -344,8 +345,8 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
s, 0)
else:
if not isinstance(s, (bytes, bytearray)):
- raise TypeError('the JSON object must be str, bytes or bytearray, '
- 'not {!r}'.format(s.__class__.__name__))
+ raise TypeError(f'the JSON object must be str, bytes or bytearray, '
+ f'not {s.__class__.__name__}')
s = s.decode(detect_encoding(s), 'surrogatepass')
if (cls is None and object_hook is None and