GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-145378: Use PyREPL as the default input console for pdb by gaogaotiantian · Pull Request #145379 · python/cpython

Conversation

@gaogaotiantian

@gaogaotiantian gaogaotiantian commented Mar 1, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Use pyrepl as the default input console for pdb #145378

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

johnslavik, DiamondMofeng, cloudy-sfu, RiverMint78, and saucoide reacted with rocket emoji
All reactions
  • 🚀 5 reactions
gaogaotiantian added 3 commits February 24, 2026 21:17
@gaogaotiantian
Use pyrepl for pdb
c23190e
@gaogaotiantian
Draft is done!
14ea66d
@gaogaotiantian
Remove unused import
7b01466
@bedevere-app bedevere-app Bot added the awaiting core review label Mar 1, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Mar 1, 2026
Use pyrepl as the default input console for pdb #145378
Closed
blurb-it Bot and others added 2 commits March 1, 2026 01:58
@blurb-it
📜🤖 Added by blurb_it.
ce2fc9a
@gaogaotiantian
Add what's new entry
4cc5801
@gaogaotiantian
gaogaotiantian requested a review from AA-Turner as a code owner March 1, 2026 02:03
@gaogaotiantian

gaogaotiantian commented Mar 1, 2026

Copy link
Copy Markdown
Member Author

@pablogsal and @ambv as the original author for the new interactive shell. Could you take a look when you have some time, thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@johnslavik
johnslavik self-requested a review March 2, 2026 19:54
tanloong
tanloong reviewed Mar 6, 2026
View reviewed changes
Comment thread Lib/pdb.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@tanloong tanloong mentioned this pull request Apr 1, 2026
PyREPL: Different Completion Behavior with GNU Readline #145392
Closed
gaogaotiantian added 2 commits April 28, 2026 22:14
@gaogaotiantian
Merge branch 'main' into pdb-pyrepl
f817371
@gaogaotiantian
Handle Ctrl+Z properly
5c3edfe
@read-the-docs-community

read-the-docs-community Bot commented Apr 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32477993 | 📁 Comparing b04b192 against main (d71e3bc)

  🔍 Preview build  

4 files changed
± contents.html
± download.html
± whatsnew/3.15.html
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@corona10 corona10 self-assigned this Apr 29, 2026
corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py Outdated
stripped = len(origline) - len(line)
begidx = self.readline_wrapper.get_begidx() - stripped
endidx = self.readline_wrapper.get_endidx() - stripped
if begidx>0:

@corona10 corona10 Apr 29, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
if begidx>0:
if begidx > 0:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py Outdated
self.message("*exit from pdb interact command*")
else:
with self._enable_rlcompleter(ns):
console = _PdbInteractiveConsole(ns, message=self.message)

@corona10 corona10 Apr 29, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is not redundant declaration from L2486?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py Outdated
console = _PdbInteractiveConsole(ns, message=self.message)
if self.pyrepl_input is not None:
from _pyrepl.simple_interact import run_multiline_interactive_console
self.message("*pdb interact start*")

@corona10 corona10 Apr 29, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nit: Please declare as common variables

banner = "*pdb interact start*"
exitmsg = "*exit from pdb interact command*"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py
return [e for e in self.displaying.get(self.curframe, {})
if e.startswith(text)]

def do_interact(self, arg):

@corona10 corona10 Apr 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

def do_interact(self, arg):
    """..."""
    ns = {**self.curframe.f_globals, **self.curframe.f_locals}
    console = _PdbInteractiveConsole(ns, message=self.message)
    banner = "*pdb interact start*"
    exitmsg = "*exit from pdb interact command*"
    if self.pyrepl_input is not None:
        console.run_interact(banner, exitmsg, use_pyrepl=True)
    else:
        with self._enable_rlcompleter(ns):
            console.run_interact(banner, exitmsg, use_pyrepl=False)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py Outdated
Comment on lines +357 to +361
if not os.getenv("PYTHON_BASIC_REPL"):
from _pyrepl.main import CAN_USE_PYREPL

return CAN_USE_PYREPL
return False

@corona10 corona10 Apr 29, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
if not os.getenv("PYTHON_BASIC_REPL"):
from _pyrepl.main import CAN_USE_PYREPL
return CAN_USE_PYREPL
return False
if os.getenv('PYTHON_BASIC_REPL'):
CAN_USE_PYREPL = False
else:
try:
from _pyrepl.main import CAN_USE_PYREPL
except ModuleNotFoundError:
CAN_USE_PYREPL = False
return CAN_USE_PYREPL

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py Outdated

self.pdb_instance = pdb_instance
self.prompt = prompt
self.console = code.InteractiveConsole()

@corona10 corona10 Apr 29, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

So this should be something like this:

class _PdbInteractiveConsole(code.InteractiveConsole):
    def __init__(self, ns=None, message=None):
        self._message = message
        super().__init__(locals=ns, local_exit=True)

    def write(self, data):
        if self._message is not None:
            self._message(data, end='')
        else:
            super().write(data)

    def _more_lines(self, text):
        # Generic Python multi-line completeness heuristic.
        # Strips pyrepl's trailing auto-indent before compiling.
        src = text.rstrip(" \t")
        n = len(src)
        if n > 0 and text[n-1] == '\n':
            text = src
        try:
            code_obj = self.compile(text, "<stdin>", "single")
        except (OverflowError, SyntaxError, ValueError):
            lines = text.splitlines(keepends=True)
            if len(lines) == 1:
                return False
            last = lines[-1]
            return ((last.startswith((" ", "\t")) or last.strip() != "")
                    and not last.endswith("\n"))
        return code_obj is None

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py Outdated

self.pdb_instance = pdb_instance
self.prompt = prompt
self.console = code.InteractiveConsole()

@corona10 corona10 Apr 29, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
self.console = code.InteractiveConsole()
self.console = _PdbInteractiveConsole()

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
corona10
corona10 reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pdb.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

corona10
corona10 requested changes Apr 29, 2026
View reviewed changes

@corona10 corona10 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Left some comments to avoid making this fragile against future _pyrepl changes.
Let’s depend only on APIs that asyncio already uses.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting core review labels Apr 29, 2026
@bedevere-app

bedevere-app Bot commented Apr 29, 2026

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gaogaotiantian
Address comments and add history
9a783dc
@gaogaotiantian

gaogaotiantian commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

@corona10 I addressed most of the comments. There are a few things left to discuss:

  1. for do_interact, we have to use run_multiline_interactive_console anyway. If you want a clearer entry I can put this logic into _PdbInteractiveConsole but we won't be able to get rid of the dependency of _pyrepl.
  2. I added the history for pdb. I think one of the pain point users have is that pdb lost all the history when it restarts. For now pdb shares the same history file with python interpreter - I don't think that's a big deal right? It kind of makes sense. We can of course use a separate file, but the existing file is controlled by PYTHON_HISTORY env var and we support it natively if we just use the same history file.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gaogaotiantian
gaogaotiantian requested a review from corona10 April 30, 2026 02:29
corona10
corona10 requested changes Apr 30, 2026
View reviewed changes

@corona10 corona10 left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

for do_interact, we have to use run_multiline_interactive_console anyway. If you want a clearer entry I can put this logic into _PdbInteractiveConsole but we won't be able to get rid of the dependency of _pyrepl.

I think that it would be fine. asyncio already depends on it.

cpython/Lib/asyncio/__main__.py

Line 125 in 1695221

run_multiline_interactive_console,

I added the history for pdb.

Could we separate the PR for this? I think that it would be another feature.
I would like to see just pdb using pyrepl feature before the beta branch cut off, but this new feature would make another noise.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gaogaotiantian
Remove history related code
b04b192
@gaogaotiantian

gaogaotiantian commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

Could we separate the PR for this? I think that it would be another feature.

Yeah sure. I was kind of hoping this could make it way it because that's one of the reasons that I wanted to use pyrepl for pdb - the inherited history. However, if you think it's a bit risky to onboard both, we can do only pyrepl for 3.15.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

corona10
corona10 approved these changes Apr 30, 2026
View reviewed changes

@corona10 corona10 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

lgtm!

Let's fix upcoming bug during the beta period
Thanks you @gaogaotiantian

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting changes labels Apr 30, 2026
@gaogaotiantian
gaogaotiantian merged commit 234c12c into python:main Apr 30, 2026
96 of 99 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 30, 2026
@ambv ambv mentioned this pull request Jul 22, 2026
gh-154467: Fix empty (Pdb) prompt when attaching to a process with pdb -p #154469
Merged
@gaogaotiantian gaogaotiantian mentioned this pull request Oct 20, 2026
Colorize pdb #113081
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@corona10 corona10 corona10 approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@johnslavik johnslavik Awaiting requested review from johnslavik
+1 more reviewer
@tanloong tanloong tanloong left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@corona10 corona10

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@gaogaotiantian @corona10 @tanloong
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.