Skip to content

Commit f14e9c7

Browse files
committed
fix(#283): Wrong result stringifying subtables and nested arrays of tables, in arrays of tables
Close #283 Signed-off-by: Frost Ming <[email protected]>
1 parent fefb29f commit f14e9c7

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

tests/test_write.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@ def test_write_inline_table_in_nested_arrays():
2424
expected = "foo = [[{a = 1}]]\n"
2525
assert expected == dumps(d)
2626
assert loads(dumps(d))["foo"] == [[{"a": 1}]]
27+
28+
29+
def test_serialize_aot_with_nested_tables():
30+
doc = {"a": [{"b": {"c": 1}}]}
31+
expected = """\
32+
[[a]]
33+
[a.b]
34+
c = 1
35+
"""
36+
assert dumps(doc) == expected
37+
assert loads(expected) == doc

tomlkit/container.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -549,21 +549,18 @@ def _render_aot(self, key, aot, prefix=None):
549549

550550
def _render_aot_table(self, table: Table, prefix: str | None = None) -> str:
551551
cur = ""
552-
553552
_key = prefix or ""
553+
open_, close = "[[", "]]"
554554

555-
if not table.is_super_table():
556-
open_, close = "[[", "]]"
557-
558-
cur += (
559-
f"{table.trivia.indent}"
560-
f"{open_}"
561-
f"{decode(_key)}"
562-
f"{close}"
563-
f"{table.trivia.comment_ws}"
564-
f"{decode(table.trivia.comment)}"
565-
f"{table.trivia.trail}"
566-
)
555+
cur += (
556+
f"{table.trivia.indent}"
557+
f"{open_}"
558+
f"{decode(_key)}"
559+
f"{close}"
560+
f"{table.trivia.comment_ws}"
561+
f"{decode(table.trivia.comment)}"
562+
f"{table.trivia.trail}"
563+
)
567564

568565
for k, v in table.value.body:
569566
if isinstance(v, Table):

0 commit comments

Comments
 (0)