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

Invalid dumps output when appending to a multiline array #146

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

Invalid dumps output when appending to a multiline array #146

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

Comments

@abravalheri
Copy link
Contributor

Hello, I noticed an unexpected output (and invalid TOML syntax) for dumps, when trying to append a dict object to an existing multiline array. Maybe this should be considered a bug?

Please find bellow the steps to reproduce the error:

>>> import tomlkit
>>> example = """\
... x = [
... ]
... """
>>> doc = tomlkit.loads(example)
>>> doc["x"].append({"name": "John Doe", "email": "john@doe.com"})
>>> doc
{'x': [{'name': 'John Doe', 'email': 'john@doe.com'}]}
>>> print(tomlkit.dumps(doc))
x = [
, name = "John Doe"
email = "john@doe.com"
]

Here we can see that the value dumped for x does not conform with the TOML syntax. I would expect the output of dumps to be similar to the following:

x = [
   {name = "John Doe", email = "john@doe.com"}
]

Please notice that even when using explicitly inline_table, there still will be errors:

>>> doc = tomlkit.loads(example)
>>> t = tomlkit.inline_table()
>>> t.append("name", "John Doe")
{'name': 'John Doe'}
>>> t.append("email", "john@doe.com")
{'name': 'John Doe', 'email': 'john@doe.com'}
>>> doc["x"].append(t)
>>> doc
{'x': [{'name': 'John Doe', 'email': 'john@doe.com'}]}
>>> print(tomlkit.dumps(doc))
x = [
, {name = "John Doe", email = "john@doe.com"}]

Here the extra initial , will cause problems when parsing the produced string.

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