You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using tomlkit to try editing an existing document while preserving the original comments and formatting as much as possible.
I noticed that when I try to replace an existing item with a more complex entry (e.g. table), the produced TOML document (via dumps) does not correspond to the underlying data structure.
The follow is a minimal example to try to reproduce this error:
>>>importtomlkit>>>example="""\... [a]... x = 1 # comment... y = 2... z = 3... """>>>doc=tomlkit.loads(example)
>>>doc
{'a': {'x': 1, 'y': 2, 'z': 3}}
>>>doc['a']['y'] = {'nested': 1}
>>>text=tomlkit.dumps(doc)
>>>doc# this is the data-structure what we expect to obtain if parsing the dumped text
{'a': {'x': 1, 'y': {'nested': 1}, 'z': 3}}
>>>tomlkit.loads(text) # here 'z' is wrongly under 'nested'. The correct would be 'z' under 'a'
{'a': {'x': 1, 'y': {'nested': 1, 'z': 3}}}
>>>print(text)
[a]
x=1# comment
[a.y]
nested=1z=3
Please notice in this example we expect the key z to still be under the a table, but the dump-ed document ends up putting z inside the nested sub-table, which is inconsistent with the underlying data-structure.
I believe the expected behaviour of dumps, after the modification would be producing the following:
[a]
x = 1# commentz = 3
[a.y]
nested = 1
or at least
[a]
x = 1# commenty = { nested = 1 }
z = 3
I am using Python 3.8.0 and tomlkit 0.7.2 on Ubuntu 18.04.5 LTS
The text was updated successfully, but these errors were encountered:
abravalheri
changed the title
Inconsistent dump when replacing existing item with nested table.
Inconsistent dumps when replacing existing item with nested table.
Sep 21, 2021
I am using tomlkit to try editing an existing document while preserving the original comments and formatting as much as possible.
I noticed that when I try to replace an existing item with a more complex entry (e.g. table), the produced TOML document (via
dumps
) does not correspond to the underlying data structure.The follow is a minimal example to try to reproduce this error:
Please notice in this example we expect the key
z
to still be under thea
table, but thedump
-ed document ends up puttingz
inside thenested
sub-table, which is inconsistent with the underlying data-structure.I believe the expected behaviour of
dumps
, after the modification would be producing the following:or at least
I am using Python 3.8.0 and tomlkit 0.7.2 on Ubuntu 18.04.5 LTS
The text was updated successfully, but these errors were encountered: