... if isinstance(obj, complex):
... return [obj.real, obj.imag]
... # Let the base class default method raise the TypeError
- ... return json.JSONEncoder.default(self, obj)
+ ... return super().default(obj)
...
>>> json.dumps(2 + 1j, cls=ComplexEncoder)
'[2.0, 1.0]'
else:
return list(iterable)
# Let the base class default method raise the TypeError
- return json.JSONEncoder.default(self, o)
+ return super().default(o)
.. method:: encode(o)
else:
return list(iterable)
# Let the base class default method raise the TypeError
- return JSONEncoder.default(self, o)
+ return super().default(o)
"""
raise TypeError(f'Object of type {o.__class__.__name__} '