]> 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 01:52:35 +0000 (21:52 -0400)
committerR David Murray <rdmurray@bitdance.com>
Mon, 18 Mar 2013 01:52:35 +0000 (21:52 -0400)
Original patch by Kushal Das.

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

index 7b69c241865f3e9d9bff493a48e5ed609d5d3ede..58eee18575ff80a95a27cfdfb53bb6fa524b9dfc 100644 (file)
@@ -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)
 
 
index e1ed21f6e70a00ce46c76e786da09f8f85849196..1d8b20c0955ddb0f4089ef16bb4d41e0de48ca9c 100644 (file)
@@ -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)
 
         """