python-poetry / tomlkit

Style-preserving TOML library for Python
MIT License
699 stars 100 forks source link

Bug in dumps with nested dicts inside of array #338

Closed jonas-w closed 7 months ago

jonas-w commented 7 months ago

I'm using NixOS, and it uses https://github.com/remarshal-project/remarshal to convert the configuration to TOML. Remarshal uses tomlkit to create the final toml file.

I want to create a languages.toml for helix e.g.:

[[language]]
name = "test"
formatter = { command = "test" }

Now in Nix which looks kinda like toml/json, I would write:

# ...
language = [
 { name = "test"; formatter = { command = "test"; }; } 
];
# ...

Which would be the same as the toml above, and which also would be the same as the following json:

{
  "languages":[
    {
      "name":"test",
      "formatter":{
        "command":"test"
      }
    }
  ]
}

But if I convert the following to toml with tomlkit I receive the following toml output:

>>> import tomlkit
>>> d = {
...   "languages":[
...     {
...       "name":"test",
...       "formatter":{
...         "command":"test"
...       }
...     }
...   ]
... }
>>> print(tomlkit.dumps(d))
[[languages]]
name = "test"

[languages.formatter]
command = "test"
jonas-w commented 7 months ago

Yikes, nvm that really is valid TOML.