Missing newline around added section
This is a similar issue to #178, but I think it's related to #352.
original_toml_str = """\
[tool.mytool]
foo = []
[project]
name = "example"
"""
# Act
toml_document = parse(original_toml_str)
toml_document["tool"]["ruff"] = {
"line-length": 88,
}
toml_str = dumps(toml_document)
And then I would expect this assertion to pass
# Assert
assert (
toml_str
== """\
[tool.mytool]
foo = []
[tool.ruff]
line-length = 88
[project]
name = "example"
"""
)
but this fails, instead we have the following value for toml_str:
[tool.mytool]
foo = []
[tool.ruff]
line-length = 88
[project]
name = "example"
The same does not occur when [project] is replaced by [tool.othertool] - I think the issue is to do with how the whitespace-adding logic checks only within a flat hierarchy, as identified by #352.
Please have a try to fix this, or I will leave this open.
There are too many strange scenes and requirements in the field of maintaining formats, this is not an urgent one.
No worries, I'll definitely have a go, since I'm keen to fix this.
I looked at this but as I came to understand the internal structure of tomlkit, I realized that the context that toml_document["project"] is present is not accessible once we've accessed toml_document["project"] (and then setting ["ruff"] within that item). As such, this really isn't possible at the moment without a major change to the internals. As such, I'm closing this issue.