Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Related to #325.
When editing a parsed TOML table, assigning a plain Python string currently replaces single quotes with double quotes:
bar = 'baz'becomesbar = "quux"after assigning"quux". This adds formatting changes to an otherwise simple configuration edit.Preserve single-line literal quoting for replacements that can be represented that way. Values containing an apostrophe, newline, or forbidden control character still use basic strings, which provide the necessary escaping. Explicit
tomlkit.string(...)values keep the caller's quote choice. New fields, multiline strings, and array element assignments keep their existing behavior.The conversion is shared by document, table, and inline-table assignment. This is needed because tables convert Python strings to TOML items before passing them to the underlying container; checking only the final replacement method would miss the original issue's table example.
Regression tests check root, ordinary, inline, and out-of-order tables, preserving comments, spacing, key order and line endings. They also check the actual values after serialization and reparsing, explicit quote choices, and values requiring escaping. These are additional checks for this change, alongside the project's existing suite.
On Windows with Python 3.12.2, all 1,088 tests pass, including 20 new regression cases (10 fail on the baseline). All six pre-commit hooks pass. Mypy reports the same 29 errors on the baseline and the fix. Alternating local measurements found about 0.98–2.50 microseconds of extra cost per string assignment (6.0–15.8%); parsing 30 fields differed by 0.25%.
Agent Drafting Metadata