Repository: sdispater/tomlkit

Issue:
removing a nested table results in generation of an additional table header
Removing a nested table will result in additional, unnecessary table header that was not present in the original TOML.

There's also a trailing newline where there was none previously, but that's probably OK, given that the number of empty lines actually stays the same.

```python
import tomlkit

test = """\
[hello.one]
number = 1

[hello.two]
number = 2
"""

data = tomlkit.parse(test)
del data["hello"]["two"]

expected = """\
[hello.one]
number = 1

"""

actual = """\
[hello]
[hello.one]
number = 1

"""

tomlkit.dumps(data) == expected  # False
tomlkit.dumps(data) == actual  # True
```

---

Tested with tomlkit 0.11.1.

Discussion:

Patch:
diff --git a/tomlkit/container.py b/tomlkit/container.py
index 606d728..1a7e541 100644
--- a/tomlkit/container.py
+++ b/tomlkit/container.py
@@ -525,7 +525,8 @@ class Container(_CustomDict):
 
         if not table.is_super_table() or (
             any(
-                not isinstance(v, (Table, AoT, Whitespace)) for _, v in table.value.body
+                not isinstance(v, (Table, AoT, Whitespace, Null))
+                for _, v in table.value.body
             )
             and not key.is_dotted()
         ):


Test patch:
diff --git a/tests/test_toml_document.py b/tests/test_toml_document.py
index 811c90c..f253706 100644
--- a/tests/test_toml_document.py
+++ b/tests/test_toml_document.py
@@ -983,3 +983,21 @@ def test_add_newline_before_super_table():
     [d.e]
     """
     assert doc.as_string() == dedent(expected)
+
+
+def test_remove_item_from_super_table():
+    content = """\
+    [hello.one]
+    a = 1
+
+    [hello.two]
+    b = 1
+    """
+    doc = parse(dedent(content))
+    del doc["hello"]["two"]
+    expected = """\
+    [hello.one]
+    a = 1
+
+    """
+    assert doc.as_string() == dedent(expected)