-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect serialization of float subclass with custom __str__ method #57
Comments
Thanks for reporting the issue. I have reproduced it locally (thanks to the easy repro!). I am a bit surprised that this hasn't been reported before. It looks like My first reaction is that That said, I view matching Also, I'll point out that you shouldn't count on |
Thanks for taking a look at this so quick. It looks like the same issue crops up for I did some searching, and found that Is there any reason why using |
Thanks for those leads! :).
I have no idea. Changing the default behavior of any public function can usually cause problems. More importantly, reaching deep into a class's private methods doesn't feel great to me. I think I can probably get equivalent behavior by actually calling |
I forgot that back in 10e4e82 I removed (the last) dependency on At any rate, in order to not reintroduce the dependency on |
[GitHub issue #57](#57) Fixed serialization for objects that subclass `int` or `float`: Previously we would use the objects __str__ implementation, but that might result in an illegal JSON5 value if the object had customized __str__ to return something illegal. Instead, we follow the lead of the `JSON` module and call `int.__repr__` or `float.__repr__` directly. While I was at it, I added tests for dumps(-inf) and dumps(nan) when those were supposed to be disallowed by `allow_nan=False`.
Okay, I've fixed this in 1f7f806 and pushed that to PyPI as v0.9.9. Please let me know if you find any issues, and thanks again! |
I have a float subclass with a customized str method, and its str output is appearing in the results of json5.dumps. Here's a simplified example:
The text was updated successfully, but these errors were encountered: