Skip to content
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

Inconsistent JSON serialization error messages #99925

Closed
fnesveda opened this issue Dec 1, 2022 · 1 comment · Fixed by #99926
Closed

Inconsistent JSON serialization error messages #99925

fnesveda opened this issue Dec 1, 2022 · 1 comment · Fixed by #99926
Labels
type-bug An unexpected behavior, bug, or error

Comments

@fnesveda
Copy link
Contributor

fnesveda commented Dec 1, 2022

Bug report

When you try to serialize a NaN, inf or -inf with json.dumps(..., allow_nan=False), the error messages are inconsistent, depending on whether you use the indent argument or not.

>>> json.dumps(float('nan'), allow_nan=False)
ValueError: Out of range float values are not JSON compliant

>>> json.dumps(float('nan'), allow_nan=False, indent=4)
ValueError: Out of range float values are not JSON compliant: nan

That is because if you don't use indent, the encoding is done in C code here,
but if you use indent, the encoding is done in pure Python code here, and the error messages are different between the two.

Your environment

  • CPython versions tested on: 3.11.0
  • Operating system and architecture: MacOS 12.6, Apple Silicon

Linked PRs

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Dec 20, 2022

Thank you for your contribution, @fnesveda.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants