Skip to content

Fix usort_stdin to only speak bytes - #359

Open
thatch wants to merge 3 commits into
facebook:mainfrom
thatch:usort-stdin-bytes
Open

Fix usort_stdin to only speak bytes#359
thatch wants to merge 3 commits into
facebook:mainfrom
thatch:usort-stdin-bytes

Conversation

@thatch

@thatch thatch commented May 1, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 1, 2026
@thatch thatch changed the title Usort stdin bytes Fix usort_stdin to only speak bytes May 1, 2026
thatch and others added 2 commits May 1, 2026 15:41
The previous code read via sys.stdin.read() (text mode, system
encoding) then passed through the deprecated usort_string() which
re-encoded as UTF-8.  A file with a PEP 263 non-UTF-8 coding
declaration would be silently corrupted.  Read sys.stdin.buffer and
write sys.stdout.buffer directly, and call usort() with raw bytes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
usort_stdin had zero test coverage.  Add StdinTest with two cases:
sorting works at all via binary stdio, and a latin-1 file comes back
as latin-1 bytes (\xb5) rather than UTF-8 (\xc2\xb5).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thatch
thatch force-pushed the usort-stdin-bytes branch from d458555 to 398ce33 Compare May 1, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant