Skip to content

Commit 29c31d2

Browse files
Fix out-of-order super-table ordering when separated by AoT (#702)
* Fix out-of-order super-table ordering when separated by AoT * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: jeff-grimes-pplx <207642104+jeff-grimes-pplx@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 669d4d6 commit 29c31d2

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎tests/test_toml_document.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,23 @@ def test_string_output_order_is_preserved_for_out_of_order_tables() -> None:
996996
assert expected == doc.as_string()
997997

998998

999+
def test_string_output_order_is_preserved_for_out_of_order_tables_separated_by_aot() -> (
1000+
None
1001+
):
1002+
content = """[tool.poetry]
1003+
name = "foo"
1004+
1005+
[[plugins]]
1006+
name = "bar"
1007+
1008+
[tool.other]
1009+
a = "b"
1010+
"""
1011+
1012+
doc = parse(content)
1013+
assert doc.as_string() == content
1014+
1015+
9991016
def test_remove_from_out_of_order_table() -> None:
10001017
content = """[a]
10011018
x = 1

‎tomlkit/container.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def _raw_append(self, key: Key | None, item: Item) -> None:
543543
self._map[key] = len(self._body)
544544

545545
self._body.append((key, item))
546-
if item.is_table() and key is not None:
546+
if isinstance(item, (Table, AoT)) and key is not None:
547547
self._table_keys.append(key)
548548

549549
if key is not None:

0 commit comments

Comments
 (0)