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
Hello, thank you very much for the latest version, fixes and improvements.
I noticed that it changed the way tomlkit used to work for creating format-aware TOML files.
Previously, I was able to create a list of commented strings with the following code:
cat <<EOS | pip-run 'tomlkit==0.11.1'import tomlkitdoc = tomlkit.document()doc.add("project", tomlkit.table())deps = tomlkit.array()deps.add_line(tomlkit.string("first"), tomlkit.string("line"), comment="first comment")deps.add_line(tomlkit.string("second_line"), comment="second comment")deps.add_line(comment="comment-only line")deps.add_line(indent="") # New line before closing bracketsdoc["project"].add("dependencies", deps)print(doc.as_string())EOS
which would generate a valid TOML string:
[project]
dependencies = [
"first", "line", # first comment"second_line", # second comment# comment-only line
]
But now the same script results in an invalid TOML string:
cat <<EOS | pip-run 'tomlkit==0.11.2'import tomlkitdoc = tomlkit.document()doc.add("project", tomlkit.table())deps = tomlkit.array()deps.add_line(tomlkit.string("first"), tomlkit.string("line"), comment="first comment")deps.add_line(tomlkit.string("second_line"), comment="second comment")deps.add_line(comment="comment-only line")deps.add_line(indent="") # New line before closing bracketsdoc["project"].add("dependencies", deps)print(doc.as_string())EOS
[project]
dependencies = [
"first", "line", # first comment"second_line", # second comment,# comment-only line
]
I also tried without success to add a comment element directly to the array to circumvent the problem:
>>>deps.add_line(tomlkit.comment("comment-only line"))
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/tmp/pip-run-vav95r9r/tomlkit/items.py", line1276, inadd_lineraiseValueError(f"item type {type(it)} is not allowed in add_line")
ValueError: itemtype<class'tomlkit.items.Comment'>isnotallowedinadd_line
If I skip the last line (only containing a comment), the syntax error don't happen.
The syntax error seems to happen for every line that contains only a comment (it does not have to be the last line in the array).
Am I doing something wrong here? Is there any other way of achieving the same result? Or is it the case of a regression in 0.11.2?
The text was updated successfully, but these errors were encountered:
Hello, thank you very much for the latest version, fixes and improvements.
I noticed that it changed the way
tomlkit
used to work for creating format-aware TOML files.Previously, I was able to create a list of commented strings with the following code:
which would generate a valid TOML string:
But now the same script results in an invalid TOML string:
I also tried without success to add a comment element directly to the array to circumvent the problem:
If I skip the last line (only containing a comment), the syntax error don't happen.
The syntax error seems to happen for every line that contains only a comment (it does not have to be the last line in the array).
Am I doing something wrong here? Is there any other way of achieving the same result? Or is it the case of a regression in 0.11.2?
The text was updated successfully, but these errors were encountered: