diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-03-18 02:06:18 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-03-18 02:06:18 (GMT) |
commit | 35893b799496c8a9d118e64b49f10ac9bf369760 (patch) | |
tree | ba99bd751ea4e1d08d524b2a9f316b28d37075c6 | |
parent | 271e56e88740cdcc2a6bddbd0894aec25f984f4e (diff) | |
download | cpython-35893b799496c8a9d118e64b49f10ac9bf369760.zip cpython-35893b799496c8a9d118e64b49f10ac9bf369760.tar.gz cpython-35893b799496c8a9d118e64b49f10ac9bf369760.tar.bz2 |
#16057: Clarify why the base method default is called in custom encoders.
Original patch by Kushal Das.
-rw-r--r-- | Doc/library/json.rst | 2 | ||||
-rw-r--r-- | Lib/json/encoder.py | 1 |
2 files changed, 3 insertions, 0 deletions
diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 648ba3a..a3c6bb0 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -84,6 +84,7 @@ Extending :class:`JSONEncoder`:: ... def default(self, obj): ... if isinstance(obj, complex): ... return [obj.real, obj.imag] + ... # Let the base class default method raise the TypeError ... return json.JSONEncoder.default(self, obj) ... >>> dumps(2 + 1j, cls=ComplexEncoder) @@ -452,6 +453,7 @@ Encoders and Decoders pass else: return list(iterable) + # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py index 4d1aaa8..f5eeed7 100644 --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -177,6 +177,7 @@ class JSONEncoder(object): pass else: return list(iterable) + # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) """ |