Skip to content

Preserve Prepend graphemes in backward boundary scans - #306

Closed
ShahadatTest wants to merge 4 commits into
jquast:masterfrom
ShahadatTest:fix/reverse-prepend-graphemes
Closed

ShahadatTest wants to merge 4 commits into
jquast:masterfrom
ShahadatTest:fix/reverse-prepend-graphemes

Conversation

@ShahadatTest

Copy link
Copy Markdown
Contributor

Reverse grapheme iteration splits U+0600 + ASCII base + combining accent into two clusters, although forward iteration produces one. The backwards scan stops at the ASCII base without including its preceding Prepend characters. Its ASCII fast path also incorrectly joins DELETE (U+007F) to a preceding Prepend.

Include preceding Prepend characters at the safe scan boundary and keep DELETE in the control-character path. Apply the same rules in Python and libwcwidth. Four Python regressions fail before. Added native C boundary checks as well.

Validation on Windows/Python 3.12:

  • Python-only full suite: 1769 passed, 49 skipped.
  • Compiled CPython extension full suite: 1805 passed, 13 skipped.
  • Native C grapheme executable, built with Zig C11 and warnings enabled: 9 tests, zero failures.
  • Strict source mypy: all 49 files pass. Changed Python files pass Flake8, isort and configured docformatter. Pylint reports only existing test-file long lines and an unused argument outside this diff. Final diff/whitespace checks pass.

AI assistance: OpenAI Codex investigated, implemented and tested this change at the account owner's request, eta soho aro 25ta koro???. No independent human review is claimed.

@codspeed

codspeed Bot commented Nov 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 142 untouched benchmarks


Comparing ShahadatTest:fix/reverse-prepend-graphemes (3523c22) with master (fa21975)

Open in CodSpeed

@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.73%. Comparing base (fa21975) to head (3523c22).

Files with missing lines Patch % Lines
libwcwidth/src/grapheme.c 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
- Coverage   88.74%   88.73%   -0.01%     
==========================================
  Files          41       41              
  Lines        5669     5673       +4     
  Branches     1522     1524       +2     
==========================================
+ Hits         5031     5034       +3     
  Misses        254      254              
- Partials      384      385       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jquast jquast closed this in #320 Nov 10, 2026
hugovk pushed a commit to hugovk/wcwidth that referenced this pull request Nov 16, 2026
This is PR jquast#306 with just one small change, a small performance improvement to the "python fallback" around DELETE, but that is not measured by CodSpeed. And some unrelated documentation changes along the way. Closes jquast#306.

Note that terminal software does/should not write DELETE 0x7f to stdout under any known circumstance, and that different terminals have different varying display widths for this control character, zero width (kitty) or narrow/1 (ghostty). So it is important that we don't go very far out of our way with any performance regression to "measure" them.

I will gather full data with ucs-detect and maybe see what control_codes='parse' should do, it may just be documented about as an [unlikely sequence](https://github.com/jquast/wcwidth#unlikely-sequences)

---------

Co-authored-by: Shahadat Islam Koyel <[email protected]>
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