🐛 Do not mutate the passed library in write_string/write_file - #614
Merged
Conversation
Middlewares passed via prepend_middleware default to in-place modification and run before the copying default unparse stack, so writing mutated the caller's library (e.g. month "January" became "jan"). Deep-copy the library once upfront unless every middleware in the stack allows in-place modification (the explicit opt-in). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
MiWeiss
force-pushed
the
fix/write-does-not-mutate-library
branch
from
September 3, 2026 20:45
ebce299 to
da956e4
Compare
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.
write_string/write_filemutated the library passed in whenever a middleware with the defaultallow_inplace_modification=Trueran before the copying default unparse stack — e.g. theprepend_middlewareexample from the docs:Fix: deep-copy the library once before running the stack, unless every middleware allows in-place modification. Guarantee:
write_string/write_filenever modify the passed library, unless every middleware in the unparse stack allows in-place modification (an all-in-place stack is the explicit opt-in). Default stack behavior unchanged; no new parameters.Tests: input unchanged after
write_string/write_filewith an in-place prepended middleware (output still transformed); default write does not mutate; all-in-place stack may mutate; copying-only stack gets no extra upfront copy. Full suite: 2725 passed, 12 skipped.🤖 Generated with Claude Code