Use ", " separator when appending to a spaced inline table - #595
Open
Ashishjob wants to merge 2 commits into
Open
Use ", " separator when appending to a spaced inline table#595Ashishjob wants to merge 2 commits into
Ashishjob wants to merge 2 commits into
Conversation
When a key is appended to a parsed inline table that already separates its
entries with ", " (comma + space), the deferred separator inserted for the new
key was a bare "," with no space. This left the table inconsistently spaced:
>>> doc = parse("a = {x = 1, y = 2}\n")
>>> doc["a"]["z"] = 3
>>> doc.as_string()
'a = {x = 1, y = 2,z = 3}\n' # note "2,z"
Insert ", " to match the surrounding style, but only when the text that will
follow the comma (the previous value's trailing trivia plus the new key's own
indent) does not already begin with a space -- so a padded table like
`{ foo = 1, bar = 2 }` keeps producing a single space rather than a double one.
Added a regression test for the compact-with-spaced-separators case.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…etry#595) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
When a key is appended to a parsed inline table whose entries are already separated with
", "(comma + space), the deferred separator inserted for the new key was a bare","with no space, leaving the table inconsistently spaced:The existing entries use
", ", and inline tables built from scratch also use", ", so the new separator is inconsistent.Fix
Insert
", "to match the surrounding style — but only when the text that will follow the comma (the previous value’s trailing trivia plus the new key’s own indent) does not already start with a space. This keeps a padded table such as{ foo = 1, bar = 2 }(whose appended key already contributes a space via its indent) from becoming double-spaced. This is a follow-up to #477, which fixed the missing comma but emitted it without the conventional space.Result:
Padded tables are unchanged:
{ foo = 1, bar = 2 }+bazstill renders{ foo = 1, bar = 2, baz = 3}.Tests
Added
test_appending_to_compact_inline_table_uses_spaced_separator; verified it fails before the change and passes after. Full suite green (373 passed,test_toml_tests.pyneeds the vendored submodule and was not run).I can add a CHANGELOG entry once you confirm the target section (there is no
Unreleasedsection currently).