Skip to content

gh-119512: Use new REPL for the code module#148261

Open
tanloong wants to merge 9 commits intopython:mainfrom
tanloong:code-pyrepl
Open

gh-119512: Use new REPL for the code module#148261
tanloong wants to merge 9 commits intopython:mainfrom
tanloong:code-pyrepl

Conversation

@tanloong
Copy link
Copy Markdown
Contributor

@tanloong tanloong commented Apr 8, 2026

This adds an optional use_pyrepl: bool|None=False parameter to code.InteractiveConsole.interact() and code.interact().

When set as True, pyrepl is used. When False (the default), the basic readline-based REPL is used. When None, pyrepl is used if available and the PYTHON_BASIC_REPL environment variable is not set.

@tanloong tanloong requested a review from AA-Turner as a code owner April 8, 2026 17:37
Copy link
Copy Markdown
Member

@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

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

Comment on lines +174 to +176
the basic readline-based REPL is used. When ``None``, pyrepl is used
automatically if available and the :envvar:`PYTHON_BASIC_REPL` environment
variable is not set.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not make None behavior - default, and get rid of the use_pyrepl option? Users can override this by setting PYTHON_BASIC_REPL.

I presume, new option was chosen on ground backward-compatibility, but new REPL is an incompatible change by itself, this is just a continuation.

So, I think it's fine to remove added option, but please wait first feedback from core developers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review!

I believe adding the use_pyrepl parameter is necessary, and it should default to False rather than None.

While the new REPL itself is a incompatible change, many third-party projects subclass code.InteractiveConsole to implement custom shells (1.2k search results on GitHub). CPython's own sqlite3 CLI also builds on code.InteractiveConsole and uses completely different syntax and completion logic from Python. Many of these 1.2k subclasses likely implement their own custom syntax and completions, just like the sqlite3 CLI.

If we removed the use_pyrepl parameter and enabled the new REPL by default, it would break those custom shells, both the official sqlite3 CLI and many third-party ones.

For backward compatibility, I think keeping use_pyrepl=False as the default is the safest approach.

Comment on lines +845 to +847
(Contributed by Hugo van Kemenade in :gh:`146292`.)


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is unrelated change, please revert.

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.

2 participants