Whole file

avakar/pytoml

The author described this change as Raise error when dump is called with non-finite floats. It counts as a record because the check below fails on the code as it stood at 23afb8a9b and passes on 3cc8cc196, with nothing else changed between the two runs.

Fix saved2017-05-07
Sharing licenceMIT · LICENSE
Change size+5 2

What the code was meant to do, written into the code itself as a save note

Raise error when dump is called with non-finite floats

The change

11 from __future__ import unicode_literals
2-import io, datetime, sys
2+import io, datetime, math, sys
33
44 if sys.version_info[0] == 3:
55 long = int
6161 if isinstance(v, int) or isinstance(v, long):
6262 return unicode(v)
6363 if isinstance(v, float):
64- return repr(v)
64+ if math.isnan(v) or math.isinf(v):
65+ raise ValueError("{0} is not a valid TOML value".format(v))
66+ else:
67+ return repr(v)
6568 elif isinstance(v, unicode) or isinstance(v, bytes):
6669 return _escape_string(v)
6770 elif isinstance(v, datetime.datetime):

The check that tells the two apart

failpass·test/test_writer.py::test_attempting_to_write_non_number_floats_raises_error[nan]

Check file test/test_writer.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it23afb8a9b361b5e0984d4ca8e05585933835614d
Broken version dated2017-05-07
Modulepytoml.writer
Units changed_format_value
Fingerprinte525cbea4f660686
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.