Skip to content

Conversation

@daniel7an
Copy link

Summary

Fixes #440

When an inline table without a trailing newline was followed by a new key-value pair added programmatically, the serialization would concatenate them on the same line:

v = tomlkit.loads('[x]\na.b = {}')
v['x']['c'] = 3
print(tomlkit.dumps(v))
# Before: a.b = {}c = 3
# After:  a.b = {}
#         c = 3

Changes

  • tomlkit/container.py: In _render_table, added a newline check before rendering simple items when the preceding content doesn't end with a newline.
  • tests/test_toml_document.py: Added regression test covering dotted keys, non-dotted keys, and trailing newline variants.

Testing

All 284 existing tests pass. New regression test added.

When an inline table without a trailing newline was followed by a new
key-value pair, the serialization would concatenate them on the same
line (e.g. 'a.b = {}c = 3' instead of 'a.b = {}\nc = 3').

This ensures a newline is inserted before rendering a simple item
when the preceding content in a table doesn't end with one.

Fixes python-poetry#440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing newline after inline table

1 participant