Skip to content

Commit

Permalink
fix: adding table to inline table
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Sep 15, 2022
1 parent 4cf8207 commit 7194dae
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def item(
elif isinstance(value, float):
return Float(value, Trivia(), str(value))
elif isinstance(value, dict):
table_constructor = InlineTable if isinstance(_parent, Array) else Table
table_constructor = (
InlineTable if isinstance(_parent, (Array, InlineTable)) else Table
)
val = table_constructor(Container(), Trivia(), False)
for k, v in sorted(
value.items(),
Expand Down Expand Up @@ -1517,7 +1519,7 @@ def __getitem__(self, key: Union[Key, str]) -> Item:

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

is_replace = key in self
self._value[key] = value
Expand Down Expand Up @@ -1581,7 +1583,7 @@ def append(self, key, _item):
Appends a (key, item) to the table.
"""
if not isinstance(_item, Item):
_item = item(_item)
_item = item(_item, _parent=self)

self._value.append(key, _item)

Expand Down Expand Up @@ -1692,7 +1694,7 @@ def append(self, key, _item):
Appends a (key, item) to the table.
"""
if not isinstance(_item, Item):
_item = item(_item)
_item = item(_item, _parent=self)

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

0 comments on commit 7194dae

Please sign in to comment.