Skip to content

Commit

Permalink
pythongh-99925: Fix inconsistency in json.dumps() error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fnesveda committed Dec 1, 2022
1 parent 0563be2 commit 94f9f59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Unify error messages in :meth:`json.dumps(float('nan'), allow_nan=False)`
between `indent=None` and `indent=<SOMETHING>`
5 changes: 3 additions & 2 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,9 +1319,10 @@ encoder_encode_float(PyEncoderObject *s, PyObject *obj)
double i = PyFloat_AS_DOUBLE(obj);
if (!Py_IS_FINITE(i)) {
if (!s->allow_nan) {
PyErr_SetString(
PyErr_Format(
PyExc_ValueError,
"Out of range float values are not JSON compliant"
"Out of range float values are not JSON compliant: %s",
PyOS_double_to_string(i, 'r', 0, 0, NULL)
);
return NULL;
}
Expand Down

0 comments on commit 94f9f59

Please sign in to comment.