Construction of OutOfOrderTableProxy can cause newlines to be inserted
robbotorigami opened this issue · 0 comments
robbotorigami commented
Minimal example for reproduction:
def test_no_whitespace():
content = dedent("""\
[a.b.c.d]
[unrelated]
[a.b.e]
""")
doc = loads(content)
doc['a']
assert dumps(doc) == content
The value of dumps(doc) is:
[a.b.c.d]
[unrelated]
[a.b.e]
The newline is added in tomlkit/container.py:187, when the [a.b.e] block is merged in with the [a.b.c.d] block. Setting the parsed flag in the container prior to the items being merged in seems to be a minimally invasive way to fix it, but I don't understand the nuance here to know if it's a good solution. I.e.
Lines 249 to 259 in 6351f3d
current = copy.deepcopy(current)
current.value.parsing(True)
for k, v in item.value.body:
current.append(k, v)
...
If this is an acceptable fix I'm happy to make a PR with the test and change, otherwise I'm happy to fix it in a different way or defer to someone with more knowledge of the library's inner workings haha.