changeset: 82724:ef8ea052bcc4 branch: 2.7 parent: 82718:44b9f59c6ea7 user: R David Murray date: Sun Mar 17 22:06:18 2013 -0400 files: Doc/library/json.rst Lib/json/encoder.py description: #16057: Clarify why the base method default is called in custom encoders. Original patch by Kushal Das. diff -r 44b9f59c6ea7 -r ef8ea052bcc4 Doc/library/json.rst --- a/Doc/library/json.rst Sun Mar 17 15:28:10 2013 -0400 +++ b/Doc/library/json.rst Sun Mar 17 22:06:18 2013 -0400 @@ -84,6 +84,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) ... >>> dumps(2 + 1j, cls=ComplexEncoder) @@ -452,6 +453,7 @@ pass else: return list(iterable) + # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) diff -r 44b9f59c6ea7 -r ef8ea052bcc4 Lib/json/encoder.py --- a/Lib/json/encoder.py Sun Mar 17 15:28:10 2013 -0400 +++ b/Lib/json/encoder.py Sun Mar 17 22:06:18 2013 -0400 @@ -177,6 +177,7 @@ pass else: return list(iterable) + # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) """

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