[Python-checkins] cpython (merge 3.3 -> default): Merge #16057: Clarify why the base method default is called in custom encoders.

r.david.murray python-checkins at python.org
Mon Mar 18 03:06:43 CET 2013


http://hg.python.org/cpython/rev/406c6fd7e753
changeset: 82723:406c6fd7e753
parent: 82720:3c3c9ad7c297
parent: 82722:5f76e7db97ac
user: R David Murray <rdmurray at bitdance.com>
date: Sun Mar 17 21:53:48 2013 -0400
summary:
 Merge #16057: Clarify why the base method default is called in custom encoders.
Original patch by Kushal Das.
files:
 Doc/library/json.rst | 2 ++
 Lib/json/encoder.py | 1 +
 2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -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 --git a/Lib/json/encoder.py b/Lib/json/encoder.py
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -166,6 +166,7 @@
 pass
 else:
 return list(iterable)
+ # Let the base class default method raise the TypeError
 return JSONEncoder.default(self, o)
 
 """
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

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