Repository navigation
fix: write the underlying characters of str subclasses in dumps() - #726
Open
haigou-web wants to merge 1 commit into
Open
haigou-web wants to merge 1 commit into
haigou-web wants to merge 1 commit into
Conversation
escape_string() called str(s), which dispatches to an overridden __str__ on a str subclass. str-based Enum members were therefore serialized as their repr-like Enum form and custom wrappers produced invalid TOML that could not be parsed back. This restores the 0.15.2 behavior lost in the single-pass escaping rewrite. String itself is unaffected: its __str__ is str.__str__, so the fast path stays as fast as before.
|
✅ Human Attestation: @haigou-web attested this PR at commit
Later pushes to this PR stay attested. Attestation page |
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
escape_string()ended withreturn str(s). For astrsubclass that dispatches to the subclass's__str__, so whatever that returns is what ends up inside the quotes. Astr-basedEnummember gives itsrepr-like form, and a custom wrapper gives anything at all:0.15.2 wrote
color = "red"andk = "shown", so this is a regression from the single-pass escaping rewrite in 0.15.3.str.__str__(s)unboxes to a plainstrwithout invoking the subclass implementation, which is what the escaping logic wants. The escaping branch already returns a plainstrviare.sub, so both paths now agree.Fixes #725
Duplicate Check
Checked all open PRs and the
escape/str subclass/enum/dumpstitle searches. The nearest ones are #653 (re-escaping across quote styles) and #694 (escape=Falsemultiline strings); neither touchesstrsubclasses inescape_string().Notes
Stringis unaffected: its__str__isstr.__str__, so the non-escaping fast path stays as fast as before.str, subclass without sequences, subclass with sequences, anddumps()round-trip throughparse()for both astr-basedEnumand a custom wrapper.809 passed.ruff checkandruff format --checkclean.[Unreleased] / Fixed.Agent Drafting Metadata