You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: OutofrangefloatvaluesarenotJSONcompliant>>>json.dumps(float('nan'), allow_nan=False, indent=4)
ValueError: OutofrangefloatvaluesarenotJSONcompliant: 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
Activity
pythongh-99925: Fix inconsistency in `json.dumps()` error messages
gh-99925: Fix inconsistency in `json.dumps()` error messages (GH-99926)
serhiy-storchaka commentedon Dec 20, 2022
Thank you for your contribution, @fnesveda.
pythongh-99925: Fix inconsistency in `json.dumps()` error messages (p…
Merged main into regmachine branch (#50)