On Aug 8, 2019, at 3:55 PM, Chris Angelico <ros...@gmail.com> wrote:

> 
> There are two broad suggestions that came out of that thread and
> others, and I think it may be worth reopening them.
> 
> 1) Should JSONEncoder (the class underlying json.dumps) natively
> support decimal.Decimal, and if so, can it avoid importing that module
> unnecessarily?
> 
> 2) Should there be a protocol obj.__json__() to return a string
> representation of an object for direct insertion into a JSON file?
> 
> I'm inclined towards the protocol, since there are protocols for
> various other encoders (eg deepcopy, pickle), and it avoids the
> problem of json importing decimal. It can also be implemented entirely
> as a third-party patch, although you'd need to subclass Decimal to add
> that method.
> 

I proposed something similar about a year ago [1].  I really like the idea
of a protocol for this.  Especially since the other encoders already use
this approach.  Should I reboot this approach?  The implementation was
really simple [2].

- dave

[1]: 
https://mail.python.org/archives/list/python-ideas@python.org/thread/ZC4OOAVDA5ZFNCSFKDNO7P3UUOXO3DCG/
[2]: https://github.com/dave-shawley/cpython/pull/2 
<https://github.com/dave-shawley/cpython/pull/2>


_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/KEUPC3YTB3YOAMRU6EHJHXSR653LG6YC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to