summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-03-17 21:53:23 -0400
committerR David Murray <rdmurray@bitdance.com>2013-03-17 21:53:23 -0400
commit1f2a49cfc610bfd7cbc85fd263295549377e8094 (patch)
tree21c57e0ff4ae7c72814adba2949921485076888f
parent3e2fe05e62e061032d81becb2f9ef1a8def54f63 (diff)
parentdd246171e483afa21f12e2a961a461e0d5119ea3 (diff)
downloadcpython-git-1f2a49cfc610bfd7cbc85fd263295549377e8094.tar.gz
Merge #16057: Clarify why the base method default is called in custom encoders.
Original patch by Kushal Das.
-rw-r--r--Doc/library/json.rst2
-rw-r--r--Lib/json/encoder.py1
2 files changed, 3 insertions, 0 deletions
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
index 7b69c24186..58eee18575 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 e1ed21f6e7..1d8b20c095 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)
"""