@@ -179,10 +179,6 @@ def item(
179
179
key = lambda i : (isinstance (i [1 ], dict ), i [0 ] if _sort_keys else 1 ),
180
180
):
181
181
val [k ] = item (v , _parent = val , _sort_keys = _sort_keys )
182
- only_child = val [next (iter (value ))] if len (value ) == 1 else None
183
- if table_constructor is Table and isinstance (only_child , (AoT , Table )):
184
- # The table becomes super table if the only child is a table or AoT.
185
- val ._is_super_table = True
186
182
187
183
return val
188
184
elif isinstance (value , (list , tuple )):
@@ -1553,7 +1549,7 @@ def __init__(
1553
1549
value : "container.Container" ,
1554
1550
trivia : Trivia ,
1555
1551
is_aot_element : bool ,
1556
- is_super_table : bool = False ,
1552
+ is_super_table : Optional [ bool ] = None ,
1557
1553
name : Optional [str ] = None ,
1558
1554
display_name : Optional [str ] = None ,
1559
1555
) -> None :
@@ -1632,7 +1628,13 @@ def is_aot_element(self) -> bool:
1632
1628
def is_super_table (self ) -> bool :
1633
1629
"""A super table is the intermediate parent of a nested table as in [a.b.c].
1634
1630
If true, it won't appear in the TOML representation."""
1635
- return self ._is_super_table
1631
+ if self ._is_super_table is not None :
1632
+ return self ._is_super_table
1633
+ # If the table has only one child and that child is a table, then it is a super table.
1634
+ if len (self ) != 1 :
1635
+ return False
1636
+ only_child = next (iter (self .values ()))
1637
+ return isinstance (only_child , (Table , AoT ))
1636
1638
1637
1639
def as_string (self ) -> str :
1638
1640
return self ._value .as_string ()
0 commit comments