Skip to content

Commit

Permalink
Fix the only child detection when creating tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Feb 9, 2022
1 parent da2a650 commit 67263ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

[Unreleased]

### Fixed

- Fix the only child detection when creating tables. ([#175](https://github.com/sdispater/tomlkit/issues/175))

## [0.9.2] - 2022-02-08

### Changed
Expand Down
8 changes: 2 additions & 6 deletions tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,8 @@ def item(
key=lambda i: (isinstance(i[1], dict), i[0] if _sort_keys else 1),
):
val[k] = item(v, _parent=val, _sort_keys=_sort_keys)
only_child = len(value) == 1 and val[next(iter(value))]
if (
table_constructor is Table
and only_child
and isinstance(only_child, (AoT, Table))
):
only_child = val[next(iter(value))] if len(value) == 1 else None
if table_constructor is Table and isinstance(only_child, (AoT, Table)):
# The table becomes super table if the only child is a table or AoT.
val._is_super_table = True

Expand Down

0 comments on commit 67263ab

Please sign in to comment.