Skip to content

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

Open
tanloong wants to merge 15 commits into
python:mainfrom
tanloong:code-pyrepl
Open

tanloong wants to merge 15 commits into
python:mainfrom
tanloong:code-pyrepl

Conversation

@tanloong

@tanloong tanloong commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

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

@skirpichev skirpichev left a comment

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.

Comment thread Doc/library/code.rst
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.

@tanloong tanloong Apr 9, 2026 •

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.

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 relies on GNU Readline for completion. If we enable the new REPL by default, its completion will break, and we will also see incorrect syntax highlighting: tokens in SQLite statements that coincide with Python keywords will be highlighted mistakenly by PyREPL. Similar issues would affect those among the 1.2k subclasses that implemented their own custom syntax and completions.

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

Comment thread Doc/whatsnew/3.15.rst Resolved
@read-the-docs-community

read-the-docs-community Bot commented May 2, 2026 •

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 10, 2026
Comment thread Lib/code.py Outdated
from _pyrepl.simple_interact import (
run_multiline_interactive_console,
)
run_multiline_interactive_console(self)

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 returns before the code that handles the banner, exit message, and local_exit. Can we keep those behaviors when use_pyrepl is true?

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.

Updated to run PyREPL in the try-finally block, which is after those handlings.

@bedevere-app

bedevere-app Bot commented Nov 26, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 27, 2026
@tanloong

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-app

bedevere-app Bot commented Nov 27, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@pablogsal: please review the changes made to this pull request.

@bedevere-app
bedevere-app Bot requested a review from pablogsal November 27, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting change review stale Stale PR or inactive for long period of time. type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants