Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

How to preserve quote style when mutating field?

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

Nobody has claimed this yet.

Assessment

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

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.

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?

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

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.

More from python-poetry/tomlkit

All issues in python-poetry/tomlkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.