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

Nested tables should be written below their parent table #88

Open
simonpercivall opened this issue Apr 12, 2017 · 2 comments · May be fixed by #275
Open

Nested tables should be written below their parent table #88

simonpercivall opened this issue Apr 12, 2017 · 2 comments · May be fixed by #275
Labels
component: encoder Related to serialising in `toml.dump` syntax: tables Related to tables type: feature A self-contained enhancement or new feature

Comments

@simonpercivall
Copy link

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
Copy link

sayanarijit commented Jan 20, 2019

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

bochecha added a commit to bochecha/toml that referenced this issue Jan 6, 2020
Currently, we first print all tables at the top level, then all nested
tables at the second level, etc…

As a result, this:

    {
        'table1': {
            'foo': 1,
            'nested': {
                'bar': 2,
            },
        },
        'table2': {
            'baz': 3,
        },
    }

… gets printed as:

    [table1]
    foo = 1

    [table2]
    baz = 3

    [table1.nested]
    bar = 2

With this commit, we print the nested tables with their parent, so the
same example from above will instead become:

    [table1]
    foo = 1

    [table1.nested]
    bar = 2

    [table2]
    baz = 3

Fixes uiri#88
@bochecha bochecha linked a pull request Jan 6, 2020 that will close this issue
bochecha added a commit to bochecha/toml that referenced this issue Jan 6, 2020
Currently, we first print all tables at the top level, then all nested
tables at the second level, etc…

As a result, this:

    {
        'table1': {
            'foo': 1,
            'nested': {
                'bar': 2,
            },
        },
        'table2': {
            'baz': 3,
        },
    }

… gets printed as:

    [table1]
    foo = 1

    [table2]
    baz = 3

    [table1.nested]
    bar = 2

With this commit, we print the nested tables with their parent, so the
same example from above will instead become:

    [table1]
    foo = 1

    [table1.nested]
    bar = 2

    [table2]
    baz = 3

Fixes uiri#88
@Lense
Copy link

Lense commented Oct 14, 2020

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.

@pradyunsg pradyunsg added component: encoder Related to serialising in `toml.dump` type: feature A self-contained enhancement or new feature syntax: tables Related to tables and removed user-customization labels Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: encoder Related to serialising in `toml.dump` syntax: tables Related to tables type: feature A self-contained enhancement or new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants