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

Incorrect string returned by dumps when moving/renaming table #144

Closed
abravalheri opened this issue Sep 19, 2021 · 0 comments · Fixed by #151
Closed

Incorrect string returned by dumps when moving/renaming table #144

abravalheri opened this issue Sep 19, 2021 · 0 comments · Fixed by #151

Comments

@abravalheri
Copy link
Contributor

Hello @sdispater, thank you again for the amazing library.

I recently noticed that there is a problem with dumps when "moving" an element of an existing parsed document. In the case of renaming an existing table, the "dumped" string keeps the old name. Please check the example bellow:

>>> import tomlkit
>>> example = """\
... ["nested.key"]
... a = 3 # comment
... """
>>> doc = tomlkit.parse(example)
>>> doc["nested"] = {}
>>> doc["nested"]["key"] = doc.pop("nested.key")
>>> doc
{'nested': {'key': {'a': 3}}}

>>> print(tomlkit.dumps(doc))

[nested]
["nested.key"]
a = 3 # comment

>>>

I would expected the "dumped" string to be the following:

[nested]
[nested.key]
a = 3 # comment

Please notice that the tables don't have to be nested, as can be seen in the example bellow:

>>> example = """\
... [x]
... a = 3 # comment
... """
>>> doc = tomlkit.parse(example)
>>> doc["y"] = doc.pop("x")
>>> doc
{'y': {'a': 3}}

>>> print(tomlkit.dumps(doc))

[x]
a = 3 # comment

>>>

I am using Python 3.8.0 and tomlkit 0.7.2 on Ubuntu 18.04.5 LTS

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

Successfully merging a pull request may close this issue.

1 participant