Skip to content

Commit 4cf8207

Browse files
authored
fix: rendering table in nested arrays (#236)
* fix: rendering table in nested arrays * fix linter issue
1 parent a0f2309 commit 4cf8207

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tests/test_write.py

+7
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ def test_escape_special_characters_in_key():
1717
expected = '"foo\\nbar" = "baz"\n'
1818
assert expected == dumps(d)
1919
assert loads(dumps(d))["foo\nbar"] == "baz"
20+
21+
22+
def test_write_inline_table_in_nested_arrays():
23+
d = {"foo": [[{"a": 1}]]}
24+
expected = "foo = [[{a = 1}]]\n" # noqa: FS003
25+
assert expected == dumps(d)
26+
assert loads(dumps(d))["foo"] == [[{"a": 1}]]

tomlkit/items.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ def item(
184184

185185
return val
186186
elif isinstance(value, (list, tuple)):
187-
if value and all(isinstance(v, dict) for v in value):
187+
if (
188+
value
189+
and all(isinstance(v, dict) for v in value)
190+
and (_parent is None or isinstance(_parent, Table))
191+
):
188192
a = AoT([])
189193
table_constructor = Table
190194
else:

0 commit comments

Comments
 (0)