From dd246171e483afa21f12e2a961a461e0d5119ea3 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Sun, 17 Mar 2013 21:52:35 -0400 Subject: [PATCH] #16057: Clarify why the base method default is called in custom encoders. Original patch by Kushal Das. --- Doc/library/json.rst | 2 ++ Lib/json/encoder.py | 1 + 2 files changed, 3 insertions(+) diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 7b69c241865..58eee18575f 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 e1ed21f6e70..1d8b20c0955 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) """