[Python-checkins] cpython (3.2): #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:40 CET 2013
http://hg.python.org/cpython/rev/5d56e1214e95
changeset: 82721:5d56e1214e95
branch: 3.2
parent: 82715:5b5a9bceb228
user: R David Murray <rdmurray at bitdance.com>
date: Sun Mar 17 21:52:35 2013 -0400
summary:
#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
@@ -83,6 +83,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)
@@ -431,6 +432,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