Skip to content

gh-142162: Make PyREPL navigate and edit by grapheme cluster#145332

Open
kovan wants to merge 2 commits intopython:mainfrom
kovan:gh-142162-pyrepl-grapheme-clusters
Open

gh-142162: Make PyREPL navigate and edit by grapheme cluster#145332
kovan wants to merge 2 commits intopython:mainfrom
kovan:gh-142162-pyrepl-grapheme-clusters

Conversation

@kovan
Copy link

@kovan kovan commented Feb 27, 2026

Summary

  • Backspace, delete, and arrow keys now operate on grapheme clusters (e.g. base character + combining accents) rather than individual Unicode codepoints, so one keypress deletes or skips an entire visual character like é (e + U+0301).
  • Adds prev_grapheme_boundary() / next_grapheme_boundary() helpers to Reader, using unicodedata.iter_graphemes() (new in 3.15) to find cluster boundaries.
  • Updates left, right, backspace, delete in commands.py and backspace_dedent in readline.py.

Test plan

  • 7 new unit tests in test_reader.py covering combining characters, multi-codepoint grapheme clusters, and ASCII regression
  • Full python -m test test_pyrepl passes (253 tests, 0 failures)
  • Interactive pty-based testing confirms correct behavior in the real REPL

🤖 Generated with Claude Code

Backspace, delete, and arrow keys now operate on grapheme clusters
(e.g. base character + combining accents) rather than individual
Unicode codepoints. This uses unicodedata.iter_graphemes() (new in
3.15) to find cluster boundaries, so one keypress deletes or skips
an entire visual character like é (e + U+0301).

Changes:
- Add prev_grapheme_boundary/next_grapheme_boundary helpers to Reader
- Update left, right, backspace, delete commands in commands.py
- Update backspace_dedent in readline.py for the non-dedent case

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The iter_graphemes API is new in 3.15 and not yet in mypy's
typeshed stubs, so mypy reports attr-defined and no-any-return
errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant