On Sun, 11 Aug 2019 20:09:41 -0400
David Shawley <daveshaw...@gmail.com>
wrote:
> 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].

I think this would be worthwhile.

Here is a use case where it may remove some pain from users'life:
https://bugs.python.org/issue24313

Regards

Antoine.

_______________________________________________
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/H6JDEMYCKO2XUXHVBGAFAOT5PXYA2DQU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to