mirror of https://github.com/python/cpython
#16057: Clarify why the base method default is called in custom encoders.
Original patch by Kushal Das.
This commit is contained in:
parent
271e56e887
commit
35893b7994
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue