summaryrefslogtreecommitdiff
path: root/simplejson/__init__.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-10 22:24:46 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2017-11-10 22:24:46 +0200
commit6df3ec19a81029ef035266a96505f814d8d6ccac (patch)
treec4933e54fc7f81b476c2ee904ebf20f050bb93ee /simplejson/__init__.py
parent138a2ff3f6db37468f3c7509f69c984792fd49a0 (diff)
downloadsimplejson-6df3ec19a81029ef035266a96505f814d8d6ccac.tar.gz
Make TypeError messages contain type name instead of a repr.
The failure depends on the type, not on the value of an object. This combines CPython's issues 26623 and 24641.
Diffstat (limited to 'simplejson/__init__.py')
-rw-r--r--simplejson/__init__.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index 2f14262..8ed9baa 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -77,7 +77,8 @@ Specializing JSON object encoding::
>>> def encode_complex(obj):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
- ... raise TypeError(repr(o) + " is not JSON serializable")
+ ... raise TypeError('Object of type %s is not JSON serializable' %
+ ... obj.__class__.__name__)
...
>>> json.dumps(2 + 1j, default=encode_complex)
'[2.0, 1.0]'