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] empty dict in array list will not be parsed #440

Open
yihengli opened this issue Apr 26, 2024 · 2 comments
Open

[BUG] empty dict in array list will not be parsed #440

yihengli opened this issue Apr 26, 2024 · 2 comments

Comments

@yihengli
Copy link

a1 = {"a": [{"name": "bob", "kwargs": {}}]}
print(toml.dumps(a1))

What I got

[[a]]
name = "bob"

I am expecting to have

[[a]]
name = "bob"
[[a.kwargs]]

Latest toml and python=3.12

Not sure if this is the intended behavior

@JamesParrott
Copy link

JamesParrott commented May 2, 2024

I don't think this one can be put down to toml's strict TOML 0.5.0 support. The 0.5.0 ABNF toml-0.5.0.zip specially caters for empty inline tables:

inline-table-keyvals = [ inline-table-keyvals-non-empty ]

This isn't the only issue with toml's code for array tables - it needs work. See #439
In the mean time, other toml writers are available.

Reproduced:

>>> import tomli_w, tomlkit, toml_tools, toml
>>> a1 = {"a": [{"name": "bob", "kwargs": {}}]}
>>> for module in (tomli_w, tomlkit, toml_tools, toml):
...   print(module.__name__); print(module.dumps(a1))
...
tomli_w
a = [
    { name = "bob", kwargs = {} },
]

tomlkit
[[a]]
name = "bob"

[a.kwargs]

toml_tools
a = [
    { name = "bob", kwargs = {} },
]

toml
[[a]]
name = "bob"

@JamesParrott
Copy link

JamesParrott commented May 2, 2024

Having said that, toml will correctly parse a sub-array-table, and give your intended output:

>>> a2 = {"a": [{"name": "bob", "kwargs": [{}]}]}
>>> for module in (tomli_w, tomlkit, toml_tools, toml):
...   print(module.__name__); print(module.dumps(a2))
...
tomli_w
[[a]]
name = "bob"
kwargs = [
    {},
]

tomlkit
[[a]]
name = "bob"

[[a.kwargs]]

toml_tools
[[a]]
name = "bob"
kwargs = [
    {},
]

toml
[[a]]
name = "bob"
[[a.kwargs]]

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

2 participants