Skip to content

Commit 8b288a5

Browse files
authoredAug 2, 2024
fix: Table header missing (#375)
1 parent b1b38b3 commit 8b288a5

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [unreleased]
44

5+
### Fixed
6+
7+
- Fix the `Table.is_super_table()` check for tables with dotted key as the only child. ([#374](https://github.com/python-poetry/tomlkit/issues/374))
8+
59
## [0.13.0] - 2024-07-10
610

711
### Changed

‎tests/test_items.py

+8
Original file line numberDiff line numberDiff line change
@@ -985,3 +985,11 @@ def test_no_extra_minus_sign():
985985
assert doc.as_string() == "a = +1.5"
986986
doc["a"] *= -1
987987
assert doc.as_string() == "a = -1.5"
988+
989+
990+
def test_serialize_table_with_dotted_key():
991+
child = api.table()
992+
child.add(api.key(("b", "c")), 1)
993+
parent = api.table()
994+
parent.add("a", child)
995+
assert parent.as_string() == "[a]\nb.c = 1\n"

‎tomlkit/items.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -1624,8 +1624,18 @@ def is_super_table(self) -> bool:
16241624
# If the table has only one child and that child is a table, then it is a super table.
16251625
if len(self) != 1:
16261626
return False
1627-
only_child = next(iter(self.values()))
1628-
return isinstance(only_child, (Table, AoT))
1627+
k, only_child = next(iter(self.items()))
1628+
if not isinstance(k, Key):
1629+
k = SingleKey(k)
1630+
index = self.value._map[k]
1631+
if isinstance(index, tuple):
1632+
return False
1633+
real_key = self.value.body[index][0]
1634+
return (
1635+
isinstance(only_child, (Table, AoT))
1636+
and real_key is not None
1637+
and not real_key.is_dotted()
1638+
)
16291639

16301640
def as_string(self) -> str:
16311641
return self._value.as_string()

0 commit comments

Comments
 (0)