res = self.loads(out)
self.assertEqual(len(res), 1)
self.assertNotEqual(res[0], res[0])
- self.assertRaises(ValueError, self.dumps, [val], allow_nan=False)
+ msg = f'Out of range float values are not JSON compliant: {val}'
+ self.assertRaisesRegex(ValueError, msg, self.dumps, [val], allow_nan=False)
class TestPyFloat(TestFloat, PyTest): pass
--- /dev/null
+Unify error messages in JSON serialization between
+``json.dumps(float('nan'), allow_nan=False)`` and ``json.dumps(float('nan'),
+allow_nan=False, indent=<SOMETHING>)``. Now both include the representation
+of the value that could not be serialized.
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: %R",
+ obj
);
return NULL;
}