From: R David Murray Date: Mon, 18 Mar 2013 02:06:18 +0000 (-0400) Subject: #16057: Clarify why the base method default is called in custom encoders. X-Git-Tag: v2.7.4rc1~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=35893b799496c8a9d118e64b49f10ac9bf369760;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 648ba3a78828..a3c6bb0efbe6 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 4d1aaa8eedfd..f5eeed75f04c 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) """