mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Merge #16057: Clarify why the base method default is called in custom encoders.
Original patch by Kushal Das.
This commit is contained in:
commit
fbb1815491
2 changed files with 3 additions and 0 deletions
|
|
@ -82,6 +82,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)
|
||||
|
|
@ -426,6 +427,7 @@ Encoders and Decoders
|
|||
pass
|
||||
else:
|
||||
return list(iterable)
|
||||
# Let the base class default method raise the TypeError
|
||||
return json.JSONEncoder.default(self, o)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue