GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — GH-145378: Use PyREPL as the default input console for pdb by gaogaotiantian · Pull Request #145379 · python/cpython Conversation
|
|
@pablogsal and @ambv as the original author for the new interactive shell. Could you take a look when you have some time, thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Documentation build overview
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
The reason will be displayed to describe this comment to others. Learn more.
| if begidx>0: | |
| if begidx > 0: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
The reason will be displayed to describe this comment to others. Learn more.
This is not redundant declaration from L2486?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
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.
There was an error while loading. Please reload this page.
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 an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| 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.
The reason will be displayed to describe this comment to others. Learn more.
| 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.
There was an error while loading. Please reload this page.
|
|
||
| self.pdb_instance = pdb_instance | ||
| self.prompt = prompt | ||
| self.console = code.InteractiveConsole() |
There was a problem 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.
There was an error while loading. Please reload this page.
|
|
||
| self.pdb_instance = pdb_instance | ||
| self.prompt = prompt | ||
| self.console = code.InteractiveConsole() |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| self.console = code.InteractiveConsole() | |
| self.console = _PdbInteractiveConsole() |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@corona10 I addressed most of the comments. There are a few things left to discuss:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.