Skip to content

Commit

Permalink
fix(#283): Wrong result stringifying subtables and nested arrays of t…
Browse files Browse the repository at this point in the history
…ables, in arrays of tables

Close #283

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Apr 27, 2023
1 parent fefb29f commit f14e9c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
11 changes: 11 additions & 0 deletions tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ def test_write_inline_table_in_nested_arrays():
expected = "foo = [[{a = 1}]]\n"
assert expected == dumps(d)
assert loads(dumps(d))["foo"] == [[{"a": 1}]]


def test_serialize_aot_with_nested_tables():
doc = {"a": [{"b": {"c": 1}}]}
expected = """\
[[a]]
[a.b]
c = 1
"""
assert dumps(doc) == expected
assert loads(expected) == doc
23 changes: 10 additions & 13 deletions tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,21 +549,18 @@ def _render_aot(self, key, aot, prefix=None):

def _render_aot_table(self, table: Table, prefix: str | None = None) -> str:
cur = ""

_key = prefix or ""
open_, close = "[[", "]]"

if not table.is_super_table():
open_, close = "[[", "]]"

cur += (
f"{table.trivia.indent}"
f"{open_}"
f"{decode(_key)}"
f"{close}"
f"{table.trivia.comment_ws}"
f"{decode(table.trivia.comment)}"
f"{table.trivia.trail}"
)
cur += (
f"{table.trivia.indent}"
f"{open_}"
f"{decode(_key)}"
f"{close}"
f"{table.trivia.comment_ws}"
f"{decode(table.trivia.comment)}"
f"{table.trivia.trail}"
)

for k, v in table.value.body:
if isinstance(v, Table):
Expand Down

0 comments on commit f14e9c7

Please sign in to comment.