Skip to content

Commit dd24617

Browse files
committed
#16057: Clarify why the base method default is called in custom encoders.
Original patch by Kushal Das.
1 parent f346041 commit dd24617

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

Doc/library/json.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Extending :class:`JSONEncoder`::
8383
... def default(self, obj):
8484
... if isinstance(obj, complex):
8585
... return [obj.real, obj.imag]
86+
... # Let the base class default method raise the TypeError
8687
... return json.JSONEncoder.default(self, obj)
8788
...
8889
>>> json.dumps(2 + 1j, cls=ComplexEncoder)
@@ -431,6 +432,7 @@ Encoders and Decoders
431432
pass
432433
else:
433434
return list(iterable)
435+
# Let the base class default method raise the TypeError
434436
return json.JSONEncoder.default(self, o)
435437

436438

Lib/json/encoder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def default(self, o):
166166
pass
167167
else:
168168
return list(iterable)
169+
# Let the base class default method raise the TypeError
169170
return JSONEncoder.default(self, o)
170171
171172
"""

0 commit comments

Comments
 (0)