Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty table dumped when number of subtables > 1 #377

Closed
pelson opened this issue Aug 12, 2024 · 1 comment · Fixed by #378
Closed

Empty table dumped when number of subtables > 1 #377

pelson opened this issue Aug 12, 2024 · 1 comment · Fixed by #378
Assignees

Comments

@pelson
Copy link

pelson commented Aug 12, 2024

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?
@frostming frostming self-assigned this Aug 14, 2024
frostming added a commit that referenced this issue Aug 14, 2024
Fixes #377

Signed-off-by: Frost Ming <me@frostming.com>
frostming added a commit that referenced this issue Aug 14, 2024
Fixes #377

Signed-off-by: Frost Ming <me@frostming.com>
@pelson
Copy link
Author

pelson commented Aug 15, 2024

Thanks for the quick fix! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants