GH-145378: Use PyREPL as the default input console for pdb#145379
GH-145378: Use PyREPL as the default input console for pdb#145379gaogaotiantian merged 9 commits intopython:mainfrom
Conversation
|
@pablogsal and @ambv as the original author for the new interactive shell. Could you take a look when you have some time, thanks! |
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.
| if begidx>0: | |
| if begidx > 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*"
| 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.
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)| 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.
| 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 |
|
|
||
| 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 = 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|
|
||
| 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() |
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: |
|
@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.
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.