Bug in dumps? Stringifying subtables and nested arrays of tables, in arrays of tables
Closed this issue · 1 comments
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
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.