Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rendering table in nested arrays #236

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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