]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#16057: Clarify why the base method default is called in custom encoders.
authorR David Murray <rdmurray@bitdance.com>
Mon, 18 Mar 2013 02:06:18 +0000 (22:06 -0400)
committerR David Murray <rdmurray@bitdance.com>
Mon, 18 Mar 2013 02:06:18 +0000 (22:06 -0400)
Original patch by Kushal Das.

Doc/library/json.rst
Lib/json/encoder.py

index 648ba3a78828e167a8c8f66a80b5a6afd3ce3e5f..a3c6bb0efbe6313380495663fd04c18f206a79b5 100644 (file)
@@ -84,6 +84,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)
     ...
     >>> dumps(2 + 1j, cls=ComplexEncoder)
@@ -452,6 +453,7 @@ Encoders and Decoders
                 pass
             else:
                 return list(iterable)
+            # Let the base class default method raise the TypeError
             return JSONEncoder.default(self, o)
 
 
index 4d1aaa8eedfd6173beea57ac09a0fa9dcda34593..f5eeed75f04c9d035a00b4d67c75b74326f0683f 100644 (file)
@@ -177,6 +177,7 @@ class JSONEncoder(object):
                     pass
                 else:
                     return list(iterable)
+                # Let the base class default method raise the TypeError
                 return JSONEncoder.default(self, o)
 
         """