Raymond Hettinger added the comment:

It is unfortunate that there doesn't seem to be a way to round-trip Decimals.  
That would seem to be a fundamental capability that we should expect to support.

I have a vague recollection that you used to be able to trick the encoder by 
returning a subclass of float with a custom __str__; however, I don't think 
that hack would work anymore because float subclasses now get coerced back to a 
regular float in order to make the json module work with Enums (which have a 
__str__ that is meaningless in JSON).

In Python 3.5, it would be nice to add a hook that affords more control than 
"cls" currently does.  Ideally, it should allow any class to special exactly 
what it wants written-out.

Another option, for Py2.7, 3.4, and 3.5 is to add direct support for decimal 
instances (much like the enum support was backported).

----------
assignee:  -> bob.ippolito
nosy: +bob.ippolito, ethan.furman, rhettinger
versions: +Python 3.4, Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23123>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to