Skip to content

Fix asciify handling of UTF-8 byte strings - #603

Closed
zechen5 wants to merge 1 commit into
mahmoud:masterfrom
zechen5:fix-asciify-utf8-bytes
Closed

zechen5 wants to merge 1 commit into
mahmoud:masterfrom
zechen5:fix-asciify-utf8-bytes

Conversation

@zechen5

@zechen5 zechen5 commented Oct 25, 2026

Copy link
Copy Markdown

The change

Fix Python 3 byte-string handling in asciify: bytes currently raise AttributeError when 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 UnicodeDecodeError even with ignore=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 -q
  • git diff --check (clean)

AI assistance

  • Harness/tooling: OpenAI dot / Codex tools, used for discovery, implementation, testing, and PR preparation.
  • Model(s): OpenAI model; the exact model identifier is unavailable.
  • Original user prompts, with English translations:

定期帮我看看,有没有什么好的开源项目可以issue/pr的,然后改好提pr。最好是Agent合并pr的项目(如openclaw)。你最多开两个subagent干这件事。

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.

Decode bytes before ASCII encoding and transliteration, document invalid UTF-8 behavior, and cover byte/string parity and ignore semantics.
@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
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.

@mahmoud mahmoud closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants