Skip to content

Commit 94f9f59

Browse files
committed
pythongh-99925: Fix inconsistency in json.dumps() error messages
1 parent 0563be2 commit 94f9f59

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Unify error messages in :meth:`json.dumps(float('nan'), allow_nan=False)`
2+
between `indent=None` and `indent=<SOMETHING>`

Modules/_json.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1319,9 +1319,10 @@ encoder_encode_float(PyEncoderObject *s, PyObject *obj)
13191319
double i = PyFloat_AS_DOUBLE(obj);
13201320
if (!Py_IS_FINITE(i)) {
13211321
if (!s->allow_nan) {
1322-
PyErr_SetString(
1322+
PyErr_Format(
13231323
PyExc_ValueError,
1324-
"Out of range float values are not JSON compliant"
1324+
"Out of range float values are not JSON compliant: %s",
1325+
PyOS_double_to_string(i, 'r', 0, 0, NULL)
13251326
);
13261327
return NULL;
13271328
}

0 commit comments

Comments
 (0)