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

Bug in dumps? Stringifying subtables and nested arrays of tables, in arrays of tables #283

Closed
JamesParrott opened this issue Apr 24, 2023 · 1 comment

Comments

@JamesParrott
Copy link

JamesParrott commented Apr 24, 2023

hi everyone. This is a fantastic library - thanks so much. I know parsers and stringifiers are challenging to get right - I'd much rather
use tomlkit than have to write my own code to stringify TOML.

During testing of my code (using Hypothesis) I came across the following behaviour. Apologies if I've misread the TOML, but
is this a bug?

Correct behaviour with no nested table, in an array of tables:

>>> print(tomlkit.dumps({'0': [{'0': False}]}))        
[[0]]
0 = false

Subtable in array of tables stringified as a nested table (no array):

>>> print(tomlkit.dumps({'0': [{'0': {'0': False}}]}))
[0.0]
0 = false

The above is not the correct toml for that object. Unless I'm mistaken, I would expect for example:

[[0]]
0 = { 0 = false}

or:

[[0]]
0.0 = false

Also unfortunately I don't think nested arrays of tables are handled correctly:

print(tomlkit.dumps({'0': [{'0': [{'0': False}]}]})) 
[[0.0]]
0 = false

I think that's just missing the outer-most array of tables definition to start with:

[[0]]

Examples of sub-tables and nested-arrays-of-tables are given in the toml spec.
https://toml.io/en/v1.0.0#array-of-tables

This was on Python 3.11 64 bit on Windows

@JamesParrott
Copy link
Author

JamesParrott commented Apr 27, 2023

Great work, and really fast - thankyou very much! [Edit] Just seen v 0.11.8. Legend.

I can confirm it's been fixed in a build from source:

>>> print(tomlkit.dumps({'0': [{'0': {'0': False}}]}))
[[0]]
[0.0]
0 = false

>>> print(tomlkit.dumps({'0': [{'0': [{'0': False}]}]}))
[[0]]
[[0.0]]
0 = false

I'm very pleased - thanks again.

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

No branches or pull requests

1 participant