python-poetry / python-poetry/tomlkit

How to preserve quote style when mutating field?

Open
#325 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
850
Forks
162
Avg merge
13m
Merged PRs (30d)
2

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Python reproduction using tomlkit 0.12.3 and inspect how parsed string values are serialized after mutation. Confirm the behavior against the shown data.toml input and define done as preserving the original single-quote style when bar is changed and written back.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.