[Python-checkins] cpython (2.7): #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:44 CET 2013


http://hg.python.org/cpython/rev/ef8ea052bcc4
changeset:   82724:ef8ea052bcc4
branch:      2.7
parent:      82718:44b9f59c6ea7
user:        R David Murray <rdmurray at bitdance.com>
date:        Sun Mar 17 22:06:18 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
@@ -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 --git a/Lib/json/encoder.py b/Lib/json/encoder.py
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -177,6 +177,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