Repository navigation
Conversation
Decode bytes before ASCII encoding and transliteration, document invalid UTF-8 behavior, and cover byte/string parity and ignore semantics.
Owner
|
asciify documents str input; bytes were never supported and the nested except is dead Python 2 code (cleaned up separately). Adding bytes decoding is a design question, not a fix. Closing. |
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.
The change
Fix Python 3 byte-string handling in
asciify: bytes currently raiseAttributeErrorwhen the function calls.encode(). Decode bytes as UTF-8 before the existing ASCII encoding and transliteration path.Document strict UTF-8 decoding and test empty/ASCII input, Unicode transliteration, replacement/ignore behavior, and string/bytes parity. Invalid UTF-8 raises
UnicodeDecodeErroreven withignore=True; that option applies only to the final ASCII output. No dependencies are added.The backstory
I've used boltons before. I had spare AI tokens and wanted to put them toward a useful contribution to the community. This bug was found during AI-assisted code inspection, rather than a production incident.
Validation
Tests were run on October 24, 2026, not rerun on October 25. Before the fix, the regression cases produced 8 failures while 7 string/existing controls passed. After the fix, the focused tests and doctests passed (70), and the full suite passed on Python 3.12.14 and 3.13.5 (692 tests plus 12 subtests on each).
Commands:
.venv/bin/python -m pytest tests/test_strutils.py --doctest-modules boltons/strutils.py -q.venv/bin/python -m pytest --doctest-modules boltons tests -q.venv313/bin/python -m pytest --doctest-modules boltons tests -qgit diff --check(clean)AI assistance
Translation: Regularly look for good open-source projects where I can contribute issues/PRs, then fix things and submit PRs. Prefer projects where agents merge PRs (such as OpenClaw). Use at most two subagents for this.
Translation: You may find problems yourself, or add a small feature.