
Aug. 15, 2019
8:35 a.m.
On Wed, 14 Aug 2019 04:21:05 +1000 Chris Angelico <rosuav@gmail.com> wrote:
That's one of the reasons that a simple solution of "make JSONEncoder respect decimal.Decimal" was rejected - it would require that the json module import decimal, which is extremely costly. Having a __json__ protocol would be less costly, but would still have a cost, so this needs to be factored in.
You can take a page from pickle: __reduce__ is not looked up on built-il types such as int, str, tuple, etc. whose serialization is hard-coded. Regards Antoine.