Skip to content

Commit

Permalink
fix: rendering table in nested arrays (#236)
Browse files Browse the repository at this point in the history
* fix: rendering table in nested arrays

* fix linter issue
  • Loading branch information
frostming committed Sep 15, 2022
1 parent a0f2309 commit 4cf8207
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ def test_escape_special_characters_in_key():
expected = '"foo\\nbar" = "baz"\n'
assert expected == dumps(d)
assert loads(dumps(d))["foo\nbar"] == "baz"


def test_write_inline_table_in_nested_arrays():
d = {"foo": [[{"a": 1}]]}
expected = "foo = [[{a = 1}]]\n" # noqa: FS003
assert expected == dumps(d)
assert loads(dumps(d))["foo"] == [[{"a": 1}]]
6 changes: 5 additions & 1 deletion tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ def item(

return val
elif isinstance(value, (list, tuple)):
if value and all(isinstance(v, dict) for v in value):
if (
value
and all(isinstance(v, dict) for v in value)
and (_parent is None or isinstance(_parent, Table))
):
a = AoT([])
table_constructor = Table
else:
Expand Down

0 comments on commit 4cf8207

Please sign in to comment.