Fix Windows stdin/stdout newline preservation - #2603
Closed
shleder wants to merge 1 commit into
Closed
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2603 +/- ##
==========================================
+ Coverage 99.33% 99.43% +0.09%
==========================================
Files 41 41
Lines 3157 3158 +1
Branches 682 683 +1
==========================================
+ Hits 3136 3140 +4
+ Misses 14 11 -3
Partials 7 7 🚀 New features to boost your workflow:
|
DanielNoord
reviewed
Jul 29, 2026
DanielNoord
left a comment
Member
There was a problem hiding this comment.
I don't think we should be reconfguring sys.stdin. main might be called programatically by other Python programs that do not want a reconfigured sys.stdin.
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
When isort processes source through stdin on Windows, the default
TextIOWrappernewline translation can convert LF input to CRLF output or introduce duplicated carriage returns. This affects normal sorting, skipped-file passthrough, check mode, and diff output.Root cause
The CLI streamed through
sys.stdinandsys.stdoutwithout disabling platform newline translation. On Windows, the standard text streams could therefore translate newlines independently of isort's own line-ending handling.Implementation
sys.stdoutwithnewline=""before processing stdin.sys.stdinwithnewline=""only when the CLI uses the real standard input.reconfigure().TextIOWrapperwithcast()for strict mypy compatibility.Regression coverage
The new regression test verifies exact LF output, exact CRLF output, non-ASCII content preservation, LF and CRLF
isort: skip_filepassthrough, sorted and unsorted--check-onlybehavior, LF diff output without introduced carriage returns, CRLF diff output without duplicated carriage returns, injected stdin streams remaining untouched, and streams withoutreconfigure()completing without a crash.Validation
The patch was applied to a pristine checkout of base commit
47c4f9819c3e92d296efe43c2f460e6742a1a75fand compared with an independent pristine checkout of the same commit.tests/unit/test_importable.py::test_importableandtests/unit/test_regressions.py::test_windows_diff_too_large_misrepresentative_issue_1348.tests/unit/test_settings.py:86: error: Module has no attribute "mkfifo" [attr-defined].git diff --checkpasses for the patch.