tomlkit icon indicating copy to clipboard operation
tomlkit copied to clipboard

How to preserve quote style when mutating field?

Open mtkennerly opened this issue 7 months ago • 0 comments

This is the same as https://github.com/sdispater/tomlkit/issues/112 , but I reproduced the issue using the current release (0.12.3). Not sure if it's a bug or if there's an option I don't know about.

Given this code:

import tomlkit
from pathlib import Path

path = Path("data.toml")

path.write_text("""
[foo]
bar = 'baz'
""")

data = tomlkit.parse(path.read_text(encoding="utf-8"))
data["foo"]["bar"] = "quux"
path.write_bytes(tomlkit.dumps(data).encode("utf-8"))

print(path.read_text(encoding="utf-8"))

Output:

[foo]
bar = "quux"

Is it possible to preserve the single quotes when mutating the field?

mtkennerly avatar Nov 18 '23 15:11 mtkennerly