Skip to content

Commit 7194dae

Browse files
committed
fix: adding table to inline table
1 parent 4cf8207 commit 7194dae

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tomlkit/items.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ def item(
170170
elif isinstance(value, float):
171171
return Float(value, Trivia(), str(value))
172172
elif isinstance(value, dict):
173-
table_constructor = InlineTable if isinstance(_parent, Array) else Table
173+
table_constructor = (
174+
InlineTable if isinstance(_parent, (Array, InlineTable)) else Table
175+
)
174176
val = table_constructor(Container(), Trivia(), False)
175177
for k, v in sorted(
176178
value.items(),
@@ -1517,7 +1519,7 @@ def __getitem__(self, key: Union[Key, str]) -> Item:
15171519

15181520
def __setitem__(self, key: Union[Key, str], value: Any) -> None:
15191521
if not isinstance(value, Item):
1520-
value = item(value)
1522+
value = item(value, _parent=self)
15211523

15221524
is_replace = key in self
15231525
self._value[key] = value
@@ -1581,7 +1583,7 @@ def append(self, key, _item):
15811583
Appends a (key, item) to the table.
15821584
"""
15831585
if not isinstance(_item, Item):
1584-
_item = item(_item)
1586+
_item = item(_item, _parent=self)
15851587

15861588
self._value.append(key, _item)
15871589

@@ -1692,7 +1694,7 @@ def append(self, key, _item):
16921694
Appends a (key, item) to the table.
16931695
"""
16941696
if not isinstance(_item, Item):
1695-
_item = item(_item)
1697+
_item = item(_item, _parent=self)
16961698

16971699
if not isinstance(_item, (Whitespace, Comment)):
16981700
if not _item.trivia.indent and len(self._value) > 0 and not self._new:

0 commit comments

Comments
 (0)