mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
gh-102980: Redirect output of pdb's interact command, add tests and improve docs (#111194)
This commit is contained in:
parent
4b125dd31a
commit
3d712a9f4c
4 changed files with 86 additions and 4 deletions
17
Lib/pdb.py
17
Lib/pdb.py
|
|
@ -207,6 +207,15 @@ class _ModuleTarget(str):
|
|||
)
|
||||
|
||||
|
||||
class _PdbInteractiveConsole(code.InteractiveConsole):
|
||||
def __init__(self, ns, message):
|
||||
self._message = message
|
||||
super().__init__(locals=ns, local_exit=True)
|
||||
|
||||
def write(self, data):
|
||||
self._message(data, end='')
|
||||
|
||||
|
||||
# Interaction prompt line will separate file and call info from code
|
||||
# text using value of line_prefix string. A newline and arrow may
|
||||
# be to your liking. You can set it once pdb is imported using the
|
||||
|
|
@ -672,8 +681,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
|
||||
# interface abstraction functions
|
||||
|
||||
def message(self, msg):
|
||||
print(msg, file=self.stdout)
|
||||
def message(self, msg, end='\n'):
|
||||
print(msg, end=end, file=self.stdout)
|
||||
|
||||
def error(self, msg):
|
||||
print('***', msg, file=self.stdout)
|
||||
|
|
@ -1786,7 +1795,9 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
contains all the (global and local) names found in the current scope.
|
||||
"""
|
||||
ns = {**self.curframe.f_globals, **self.curframe_locals}
|
||||
code.interact("*interactive*", local=ns, local_exit=True)
|
||||
console = _PdbInteractiveConsole(ns, message=self.message)
|
||||
console.interact(banner="*pdb interact start*",
|
||||
exitmsg="*exit from pdb interact command*")
|
||||
|
||||
def do_alias(self, arg):
|
||||
"""alias [name [command]]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue