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.
Projectavakar/pytoml
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
| 1 | 1 | from __future__ import unicode_literals | |
| 2 | - | import io, datetime, sys | |
| 2 | + | import io, datetime, math, sys | |
| 3 | 3 | ||
| 4 | 4 | if sys.version_info[0] == 3: | |
| 5 | 5 | long = int | |
| ⋯ | |||
| 61 | 61 | if isinstance(v, int) or isinstance(v, long): | |
| 62 | 62 | return unicode(v) | |
| 63 | 63 | 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) | |
| 65 | 68 | elif isinstance(v, unicode) or isinstance(v, bytes): | |
| 66 | 69 | return _escape_string(v) | |
| 67 | 70 | elif isinstance(v, datetime.datetime): | |
The check that tells the two apart
fail→pass·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.