Repository navigation
Conversation
apply_text_edits wrote with write_text() in universal-newline mode, so every '\\n' became os.linesep: CRLF files became CR CR LF and LF files became CRLF, while the tool reported newline: preserve. Read and write the exact bytes/newlines.
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.
Problem
apply_text_edits()writes the edited text withtarget.write_text(rendered, encoding=used_encoding). Text mode (newline=None) translates every\ninrenderedtoos.linesep, and the matching read path (path.read_text(...)) already translated the file on the way in, so_detect_newlinenever sees the real style:\r\r\n(or LF on POSIX);…while the tool still answers
newline: newline_style, claiming the style was preserved. One single-line edit therefore rewrites the line endings of the whole file.Fix
Write with
newline="", and read the exact bytes in the explicit-encoding branch so the detected newline reflects the file.Tests
tests/test_file_tool_line_endings.py(4 tests): LF, CRLF and CR files keep their endings through an edit, and the reportednewlinematches.