changeset: 82723:406c6fd7e753 parent: 82720:3c3c9ad7c297 parent: 82722:5f76e7db97ac user: R David Murray date: Sun Mar 17 21:53:48 2013 -0400 files: Doc/library/json.rst Lib/json/encoder.py description: Merge #16057: Clarify why the base method default is called in custom encoders. Original patch by Kushal Das. diff -r 3c3c9ad7c297 -r 406c6fd7e753 Doc/library/json.rst --- a/Doc/library/json.rst Sun Mar 17 15:49:21 2013 -0700 +++ b/Doc/library/json.rst Sun Mar 17 21:53:48 2013 -0400 @@ -82,6 +82,7 @@ ... 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) @@ -426,6 +427,7 @@ pass else: return list(iterable) + # Let the base class default method raise the TypeError return json.JSONEncoder.default(self, o) diff -r 3c3c9ad7c297 -r 406c6fd7e753 Lib/json/encoder.py --- a/Lib/json/encoder.py Sun Mar 17 15:49:21 2013 -0700 +++ b/Lib/json/encoder.py Sun Mar 17 21:53:48 2013 -0400 @@ -166,6 +166,7 @@ pass else: return list(iterable) + # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) """

AltStyle によって変換されたページ (->オリジナル) /