Skip to content

gh-130472: Remove readline-only hacks from PyREPL completions#148161

Merged
pablogsal merged 1 commit intopython:mainfrom
pablogsal:gh-130472
Apr 6, 2026
Merged

gh-130472: Remove readline-only hacks from PyREPL completions#148161
pablogsal merged 1 commit intopython:mainfrom
pablogsal:gh-130472

Conversation

@pablogsal
Copy link
Copy Markdown
Member

@pablogsal pablogsal commented Apr 6, 2026

PyREPL was still carrying over two readline-specific tricks from the
fancy completer: a synthetic CSI prefix to influence sorting and a fake
blank completion entry to suppress readline's prefix insertion. Those
workarounds are not appropriate in PyREPL because the reader already
owns completion ordering and menu rendering, so the fake entries leaked
into the UI as real terminal attributes and empty menu cells.

Sort completion candidates in ReadlineAlikeReader by their visible text
with stripcolor(), and let the fancy completer return only real matches.
That keeps colored completions stable without emitting bogus escape
sequences, removes the empty completion slot, and adds regression tests
for both the low-level completer output and the reader integration.

PyREPL was still carrying over two readline-specific tricks from the
fancy completer: a synthetic CSI prefix to influence sorting and a fake
blank completion entry to suppress readline's prefix insertion. Those
workarounds are not appropriate in PyREPL because the reader already
owns completion ordering and menu rendering, so the fake entries leaked
into the UI as real terminal attributes and empty menu cells.

Sort completion candidates in ReadlineAlikeReader by their visible text
with stripcolor(), and let the fancy completer return only real matches.
That keeps colored completions stable without emitting bogus escape
sequences, removes the empty completion slot, and adds regression tests
for both the low-level completer output and the reader integration.
@StanFromIreland
Copy link
Copy Markdown
Member

It fixes my issues,

image

is it possible to have deeper alphabetic sorting, above all of the Py_ are jumbled together?

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Apr 6, 2026

Also good now:

image

is it possible to have deeper alphabetic sorting, above all of the Py_ are jumbled together?

Looks like it's case-sensitive alphabetical, do you mean case-insensitive?

@StanFromIreland
Copy link
Copy Markdown
Member

StanFromIreland commented Apr 6, 2026

case-sensitive alphabetical

I mean case-sensitive alphabetical, but to not stop at the second character, _.

@pablogsal
Copy link
Copy Markdown
Member Author

I mean case-sensitive alphabetical, but to not stop at the second character, _.

Let me see what I can do

@pablogsal
Copy link
Copy Markdown
Member Author

Check the latest commit. If you mean something different you are going to need to explain in more detail what you have in mind :)

Copy link
Copy Markdown
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, you can revert the last commit, the current is better. I reviewed a7f83bd, LGTM

@pablogsal pablogsal enabled auto-merge (squash) April 6, 2026 14:29
@pablogsal pablogsal merged commit f8293fa into python:main Apr 6, 2026
114 checks passed
@pablogsal pablogsal deleted the gh-130472 branch April 6, 2026 14:57
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.

3 participants