Uh oh!
There was an error while loading. Please reload this page.
GH-145378: Use PyREPL as the default input console for pdb - #145379
Conversation
gaogaotiantian
commented
Mar 1, 2026
@pablogsal and @ambv as the original author for the new interactive shell. Could you take a look when you have some time, thanks! |
Uh oh!
There was an error while loading. Please reload this page.
Documentation build overview
|
| stripped = len(origline) - len(line) | ||
| begidx = self.readline_wrapper.get_begidx() - stripped | ||
| endidx = self.readline_wrapper.get_endidx() - stripped | ||
| if begidx>0: |
There was a problem hiding this comment.
| ifbegidx>0: | |
| ifbegidx>0: |
| self.message("*exit from pdb interact command*") | ||
| else: | ||
| with self._enable_rlcompleter(ns): | ||
| console = _PdbInteractiveConsole(ns, message=self.message) |
There was a problem hiding this comment.
This is not redundant declaration from L2486?
| 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*") |
There was a problem hiding this comment.
Nit: Please declare as common variables
banner = "*pdb interact start*"
exitmsg = "*exit from pdb interact command*"
Uh oh!
There was an error while loading. Please reload this page.
| return [e for e in self.displaying.get(self.curframe, {}) | ||
| if e.startswith(text)] | ||
| def do_interact(self, arg): |
There was a problem hiding this comment.
defdo_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*"ifself.pyrepl_inputisnotNone:
console.run_interact(banner, exitmsg, use_pyrepl=True)
else:
withself._enable_rlcompleter(ns):
console.run_interact(banner, exitmsg, use_pyrepl=False)| if not os.getenv("PYTHON_BASIC_REPL"): | ||
| from _pyrepl.main import CAN_USE_PYREPL | ||
| return CAN_USE_PYREPL | ||
| return False |
There was a problem hiding this comment.
| ifnotos.getenv("PYTHON_BASIC_REPL"): | |
| from_pyrepl.mainimportCAN_USE_PYREPL | |
| returnCAN_USE_PYREPL | |
| returnFalse | |
| ifos.getenv('PYTHON_BASIC_REPL'): | |
| CAN_USE_PYREPL=False | |
| else: | |
| try: | |
| from_pyrepl.mainimportCAN_USE_PYREPL | |
| exceptModuleNotFoundError: | |
| CAN_USE_PYREPL=False | |
| returnCAN_USE_PYREPL |
| self.pdb_instance = pdb_instance | ||
| self.prompt = prompt | ||
| self.console = code.InteractiveConsole() |
There was a problem hiding this comment.
So this should be something like this:
class_PdbInteractiveConsole(code.InteractiveConsole):
def__init__(self, ns=None, message=None):
self._message=messagesuper().__init__(locals=ns, local_exit=True)
defwrite(self, data):
ifself._messageisnotNone:
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)
ifn>0andtext[n-1] =='\n':
text=srctry:
code_obj=self.compile(text, "<stdin>", "single")
except (OverflowError, SyntaxError, ValueError):
lines=text.splitlines(keepends=True)
iflen(lines) ==1:
returnFalselast=lines[-1]
return ((last.startswith((" ", "\t")) orlast.strip() !="")
andnotlast.endswith("\n"))
returncode_objisNone| self.pdb_instance = pdb_instance | ||
| self.prompt = prompt | ||
| self.console = code.InteractiveConsole() |
There was a problem hiding this comment.
| self.console=code.InteractiveConsole() | |
| self.console=_PdbInteractiveConsole() |
Uh oh!
There was an error while loading. Please reload this page.
corona10
left a comment
There was a problem hiding this comment.
Left some comments to avoid making this fragile against future _pyrepl changes.
Let’s depend only on APIs that asyncio already uses.
When you're done making the requested changes, leave the comment: |
gaogaotiantian
commented
Apr 30, 2026
@corona10 I addressed most of the comments. There are a few things left to discuss:
|
There was a problem hiding this comment.
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
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.
gaogaotiantian
commented
Apr 30, 2026
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 |
corona10
left a comment
There was a problem hiding this comment.
lgtm!
Let's fix upcoming bug during the beta period
Thanks you @gaogaotiantian
Uh oh!
There was an error while loading. Please reload this page.