Summary
In tomlkit 0.15.0, appending a new key to a parsed inline table that already contains multiple key/value pairs can produce invalid TOML: the newly appended key is serialized without a comma separator before it.
This appears to be a regression from 0.14.0.
Reproducer
import tomlkit
print(tomlkit.__version__)
doc = tomlkit.parse('x = { a = 1, b = 2 }\n')
doc['x']['c'] = 3
out = doc.as_string()
print(out, end='')
tomlkit.parse(out)
Actual behavior on 0.15.0
0.15.0
x = { a = 1, b = 2 c = 3}
Traceback ...
tomlkit.exceptions.UnexpectedCharError: Unexpected character: 'c' at line 1 col 19
The serialized TOML is invalid because the inline table is missing a comma between b = 2 and c = 3.
Expected behavior
as_string() should produce valid TOML, for example:
x = { a = 1, b = 2, c = 3}
The same reproducer works on 0.14.0:
0.14.0
x = { a = 1, b = 2, c = 3}
Environment
- Python: 3.13.2
- tomlkit: 0.15.0
- Last known good version tested: 0.14.0
Notes
This only seems to happen when mutating a parsed inline table with multiple existing entries. Creating/replacing an inline table from scratch still serializes commas correctly.
Summary
In tomlkit 0.15.0, appending a new key to a parsed inline table that already contains multiple key/value pairs can produce invalid TOML: the newly appended key is serialized without a comma separator before it.
This appears to be a regression from 0.14.0.
Reproducer
Actual behavior on 0.15.0
The serialized TOML is invalid because the inline table is missing a comma between
b = 2andc = 3.Expected behavior
as_string()should produce valid TOML, for example:The same reproducer works on 0.14.0:
Environment
Notes
This only seems to happen when mutating a parsed inline table with multiple existing entries. Creating/replacing an inline table from scratch still serializes commas correctly.