Skip to content

Commit d4e1ecd

Browse files
authored
fix: add newline indentation after existing items in Container class (#421)
Fix #387 Signed-off-by: Frost Ming <[email protected]>
1 parent e3b7332 commit d4e1ecd

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Fixed
1010

1111
- Fix non-existing key error when deleting an item from an out-of-order table. ([#383](https://github.com/python-poetry/tomlkit/issues/383))
12+
- Ensure newline is added between the plain values and the first table. ([#387](https://github.com/python-poetry/tomlkit/issues/387))
1213
- Fix repeated whitespace when removing an array item. ([#405](https://github.com/python-poetry/tomlkit/issues/405))
1314
- Fix invalid serialization after removing array item if the comma is on its own line. ([#408](https://github.com/python-poetry/tomlkit/issues/408))
1415
- Fix serialization of a nested dotted key table. ([#411](https://github.com/python-poetry/tomlkit/issues/411))

tests/test_toml_document.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ def test_update_nested_out_of_order_table():
692692
== """\
693693
[root1.root2.a]
694694
tmp = "hi"
695+
695696
[root1.root2.a.b.c]
696697
value = 2
697698
[WALRUS]
@@ -814,6 +815,7 @@ def test_replace_table_with_value():
814815
assert (
815816
doc.as_string()
816817
== """bar = 42
818+
817819
[foo]
818820
a = 1
819821

tomlkit/container.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ def append(
289289
last_index = self._get_last_index_before_table()
290290

291291
if last_index < len(self._body):
292+
after_item = self._body[last_index][1]
293+
if not (
294+
isinstance(after_item, Whitespace)
295+
or "\n" in after_item.trivia.indent
296+
):
297+
after_item.trivia.indent = "\n" + after_item.trivia.indent
292298
return self._insert_at(last_index, key, item)
293299
else:
294300
previous_item = self._body[-1][1]

0 commit comments

Comments
 (0)