Repository navigation
Conversation
|
✅ Human Attestation: @Harp404 attested this PR at commit
Later pushes to this PR stay attested. Attestation page |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
131d3f6 to
dfa751c
Compare
Giacomo117
left a comment
There was a problem hiding this comment.
Thanks for this! I merged it with today's master: no conflicts, all 1529 tests pass, and the 13 new tests fail without the fix.
The 5 cases in the description give invalid TOML or a different value on master and are all correct with this PR. += on k = 'it' # comment now writes valid TOML and keeps the comment. I also tried 30,000 random additions across the four string types and none produced invalid TOML.
The only problem I found is the one in the inline comment. It's not your fault: #726 was merged after you opened this PR. A test with a str enum might be worth adding.
| ) | ||
| # The raw text of a String of another type is spelled for its own | ||
| # delimiters: append its value instead. | ||
| appended = str(other) |
There was a problem hiding this comment.
Merged with today's master, this line brings back the bug fixed in #726. With Color a str-based enum, string("a") + Color.RED writes "aColor.RED", while master writes "ared". Same with += and with all four string types.
Using str.__str__(other), like #726 does, fixes it and the full suite still passes (1529 tests).
String.__add__ spliced the appended text into the raw TOML of the left string. That wrote invalid TOML or a different value when a literal string could not hold the result, when the right operand was a String of another quoting style, and at the edges of multiline strings (a leading newline, adjacent quotes, whitespace after a line ending backslash). Fall back to a basic string when a literal string cannot hold the result, append a String of another style by value, and handle the multiline edge cases.
dfa751c to
a267932
Compare
String.__add__pastes the other operand into the left string's TOML source as-is, so the result can be invalid TOML or read back as a different value:string("lit", literal=True) + "'q"writes'lit'q'(a literal string cannot escape')string("a") + string('b"c', literal=True)writes"ab"c"string("a", literal=True) + string("b\nc")writes'ab\nc', which reads back with a literal backslashstring('a""', multiline=True) + '"'writes"""a""""""string("", multiline=True) + "\nb"loses the newline (the parser drops a newline right after the opening""")Now a literal string that can't hold the result becomes a basic string of the same kind (the same fallback as #627), an operand with a different quote style is added by value instead of by its source text, and the multiline join cases are handled. The string's trivia/comment is kept.
Tests:
test_string_add_keeps_valid_toml(12 cases) andtest_string_add_literal_fallback_keeps_commentfail on master and pass with this change; the full suite passes. I also fuzzed random additions (180k across 6 seeds) and checked every result withtomlliband tomlkit's own parser: none were invalid or changed value.Duplicate Check
Agent Drafting Metadata