uiri / toml

Python lib for TOML
MIT License
1.08k stars 189 forks source link

Nested tables should be written below their parent table #88

Open simonpercivall opened 7 years ago

simonpercivall commented 7 years ago

Though not a requirement of the spec, it would be a very nice feature of this library to, when encoding nested dictionaries, write nested tables directly below their parent table, instead of first all top-level sections then the next level, then the next.

sayanarijit commented 5 years ago

We can use dump order strategies for this. e.g.

toml.dumps(data, nested_order=toml.NESTED_FIRST)   # As suggested in this PR.
toml.dumps(data, nested_order=toml.NESTED_LAST)    # Default/current strategy
Lense commented 3 years ago

The v1.0.0 rc has a preferred ordering:

https://toml.io/en/v1.0.0-rc.3#table

Defining tables out-of-order is discouraged.

# VALID BUT DISCOURAGED
[fruit.apple]
[animal]
[fruit.orange]
# RECOMMENDED
[fruit.apple]
[fruit.orange]
[animal]

I support the approach in #275.