Skip to content

Empty table dumped when number of subtables > 1 #377

Closed

Description

@pelson

With the following code and tomlkit 0.13:

import tomlkit

doc = tomlkit.document()

def add_table(parent, name):
    parent.add(name, tomlkit.table())
    return parent[name]


root = add_table(doc, 'root')

first = add_table(root, "first")

print(">>> WITH A SINGLE TABLE:")
print(tomlkit.dumps(doc))
print()

second = add_table(root, "second")

print(">>> WITH A DOUBLE TABLE:")
print(tomlkit.dumps(doc))

You get:

>>> WITH A SINGLE TABLE:
[root.first]


>>> WITH A DOUBLE TABLE:
[root]
[root.first]

[root.second]

Notice that in the second example, we get an empty [root] table, whereas in the first case we do not. In both cases, I would not expect the table to be shown (and perhaps, none of the tables should be shown...).

  • Is this behaviour expected, and the intended behaviour of tomlkit
  • Is there a way to define a table which should not be shown if it remains empty?

Activity

  1. self-assigned this
    on Aug 14, 2024
  2. added a commit that references this issue on Aug 14, 2024
    c579b14
  3. added a commit that references this issue on Aug 14, 2024
    28fe6ec
  4. pelson commented on Aug 15, 2024

    @pelson
    Author

    Thanks for the quick fix! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions