Skip to content

gh-130472: Integrate fancycompleter with the new repl, to get colored tab completions#130473

Merged
pablogsal merged 49 commits intopython:mainfrom
antocuni:antocuni/fancycompleter
Apr 5, 2026
Merged

gh-130472: Integrate fancycompleter with the new repl, to get colored tab completions#130473
pablogsal merged 49 commits intopython:mainfrom
antocuni:antocuni/fancycompleter

Conversation

@antocuni
Copy link
Copy Markdown
Contributor

@antocuni antocuni commented Feb 22, 2025

As the title says, this is (WIP) to integrate fancycompleter into the new REPL.

Copy link
Copy Markdown
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Exciting! Just some nits.

@antocuni
Copy link
Copy Markdown
Contributor Author

Assuming the tests are going to pass (last famous words), this is ready to review.
So far I have tested it only on my linux machine, if anybody has access to windows and macos it would be nice to do a "visual check" that things are going as intended.
This is how it looks like on my machine:

image

Compared to the initial version, I'm now using _colorize.get_theme() to get the colors.
I'm not 100% sure about _colorize.FancyCompleter though: for other use cases using a dataclass seems a good idea because the set of keys is known in advance, but here you potentially have an open ended set of types (ideally, users should be able to add their own types to the config).
So maybe we could turn the dataclass into a plain dict? This would also solve the ugly workaround to allow coloring method-wrapper here:
https://github.com/antocuni/cpython/blob/13a269807d24c4df0ec7bdca7b04369171c0db16/Lib/_pyrepl/fancycompleter.py#L153-L160

/cc @ambv as I think he's the one responsible for themes.

@antocuni antocuni marked this pull request as ready for review September 19, 2025 14:15
@antocuni
Copy link
Copy Markdown
Contributor Author

Also, I'm getting a warning from the doc builder but I'm not sure how to fix:


Warning: py:mod reference target not found: _pyrepl.fancycompleter [ref.mod]
/home/runner/work/cpython/cpython/Doc/using/cmdline.rst:1288: WARNING: py:mod reference target not found: _pyrepl.fancycompleter [ref.mod]

_pyrepl.fancycompleter is a module, do I need to add it somewhere else?

@StanFromIreland
Copy link
Copy Markdown
Member

_pyrepl.fancycompleter is a module, do I need to add it somewhere else?

Yes, but it is not documented. You can add an exclamation mark at the start to remove the link.

@sstandre
Copy link
Copy Markdown
Contributor

So far I have tested it only on my linux machine, if anybody has access to windows and macos it would be nice to do a "visual check" that things are going as intended.

I tested it on Windows 10 using the Windows Terminal app.
This is using Powershell with Campbell theme:
image

@pablogsal pablogsal force-pushed the antocuni/fancycompleter branch from 7d2c790 to 9b9b37d Compare April 5, 2026 13:27
Keep pyrepl completion logic working on the uncolored completion text.
The reader now strips ANSI escapes before comparing the typed stem,
inserting a sole completion, computing the shared prefix, and filtering
an open completion menu. This fixes colored completions that would stop
refining correctly once more characters were typed.

Restore readline's callable postfix behavior for attribute completions by
routing single attribute matches through rlcompleter's callable postfix
logic while keeping the full expr.attr stem for menu refinement. Global
completion also treats soft keywords as keywords instead of trying to
evaluate them.

Avoid side effects while probing attribute values for coloring by not
forcing property access and by preserving lazy module imports. Also make
the fake color-sorting escape prefix round-trip cleanly once the match
index grows past three digits.

Only honor PYTHON_BASIC_COMPLETER when the environment is enabled, so
pyrepl setup now respects -E / sys.flags.ignore_environment. Add
regression tests for the reader behavior, callable attribute completion,
property and lazy-import safety, large color-sort prefixes, and the -E
setup path.
@pablogsal
Copy link
Copy Markdown
Member

Thanks for the great work on this, @antocuni . I rebased the branch and added a handful of follow-up fixes around the fancycompleter integration, including some edge cases and extra regression coverage.

This is in good shape now, and I’m planning to land it soon so it makes the next release.

Copy link
Copy Markdown
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

LGTM after my fixes

@pablogsal pablogsal enabled auto-merge (squash) April 5, 2026 13:58
@pablogsal pablogsal merged commit 1c4408a into python:main Apr 5, 2026
64 checks passed
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.