hukkin/tomli-w

Question, is there any plans, interest regarding AoT support?

abravalheri opened this issue · 2 comments

Hello, thank you very much for the package!

I was wondering if tomli-w has Array of Tables (AoT) support (or at least if you consider this feature something nice to have in the roadmap).
For example, if we take the following conversion:

>>> import tomli_w
>>> example = {'table': {'nested_table': [{'array_options': [1, 2, 3]}, {'another_array': [1, 2]}, {'c': 3}]}}
>>> print(tomli_w.dumps(example))
[table]
nested_table = [
    { array_options = [
    1,
    2,
    3,
] },
    { another_array = [
    1,
    2,
] },
    { c = 3 },
]

The output looks very weird, and a AoT would make it much easier to read... I had to check the standards to believe it is not following a wrong syntax 😝 (it is explicitly discouraged to have line breaks inside inline tables, though)

In the case AoT is supported, the following would read much nicer:

[[table.nested_table]]
array_options = [
    1,
    2,
    3,
]

[[table.nested_table]]
another_array = [
    1,
    2,
]

[[table.nested_table]]
c = 3

In can see that currently nested tables are automatically handled:

>>> example = {'table': {'nested_table': {'value': 42}}}
>>> print(tomli_w.dumps(example))
[table.nested_table]
value = 42
# instead of "[table]\nnested_table = { value = 42 }"

which conceptually is not very different from AoT, right?

Hi, thanks for the issue!

I think any style improving changes would be nice to have. That said, the biggest goal of this package for me is having exactly 0 bugs. A simpler style (and fewer lines of code) make that a more realistic goal.

I won't be working on this myself. If someone else does, I'll consider merging it if it doesn't add too much complexity, is well tested, and seems 100% bug free.

Generally I'd advise using tomlkit package instead if formatting style is important for you.

AoT support added in #15

Thanks @abravalheri