From: R David Murray Date: Mon, 18 Mar 2013 01:52:35 +0000 (-0400) Subject: #16057: Clarify why the base method default is called in custom encoders. X-Git-Tag: v3.2.4rc1~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dd246171e483afa21f12e2a961a461e0d5119ea3;p=thirdparty%2FPython%2Fcpython.git #16057: Clarify why the base method default is called in custom encoders. Original patch by Kushal Das. --- diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 7b69c241865f..58eee18575ff 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -83,6 +83,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) ... >>> json.dumps(2 + 1j, cls=ComplexEncoder) @@ -431,6 +432,7 @@ Encoders and Decoders pass else: return list(iterable) + # Let the base class default method raise the TypeError return json.JSONEncoder.default(self, o) diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py index e1ed21f6e70a..1d8b20c0955d 100644 --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -166,6 +166,7 @@ class JSONEncoder(object): pass else: return list(iterable) + # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) """