mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
GH-106734: Disable tab completion in pdb's multiline mode (GH-106735)
This commit is contained in:
parent
b88d9e75f6
commit
391f3e3ca9
2 changed files with 39 additions and 21 deletions
59
Lib/pdb.py
59
Lib/pdb.py
|
|
@ -514,6 +514,22 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
if obj is not None:
|
if obj is not None:
|
||||||
self.message(repr(obj))
|
self.message(repr(obj))
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def _disable_tab_completion(self):
|
||||||
|
if self.use_rawinput and self.completekey == 'tab':
|
||||||
|
try:
|
||||||
|
import readline
|
||||||
|
except ImportError:
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
readline.parse_and_bind('tab: self-insert')
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
readline.parse_and_bind('tab: complete')
|
||||||
|
else:
|
||||||
|
yield
|
||||||
|
|
||||||
def default(self, line):
|
def default(self, line):
|
||||||
if line[:1] == '!': line = line[1:].strip()
|
if line[:1] == '!': line = line[1:].strip()
|
||||||
locals = self.curframe_locals
|
locals = self.curframe_locals
|
||||||
|
|
@ -521,28 +537,29 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
try:
|
try:
|
||||||
if (code := codeop.compile_command(line + '\n', '<stdin>', 'single')) is None:
|
if (code := codeop.compile_command(line + '\n', '<stdin>', 'single')) is None:
|
||||||
# Multi-line mode
|
# Multi-line mode
|
||||||
buffer = line
|
with self._disable_tab_completion():
|
||||||
continue_prompt = "... "
|
buffer = line
|
||||||
while (code := codeop.compile_command(buffer, '<stdin>', 'single')) is None:
|
continue_prompt = "... "
|
||||||
if self.use_rawinput:
|
while (code := codeop.compile_command(buffer, '<stdin>', 'single')) is None:
|
||||||
try:
|
if self.use_rawinput:
|
||||||
line = input(continue_prompt)
|
try:
|
||||||
except (EOFError, KeyboardInterrupt):
|
line = input(continue_prompt)
|
||||||
self.lastcmd = ""
|
except (EOFError, KeyboardInterrupt):
|
||||||
print('\n')
|
self.lastcmd = ""
|
||||||
return
|
print('\n')
|
||||||
else:
|
return
|
||||||
self.stdout.write(continue_prompt)
|
|
||||||
self.stdout.flush()
|
|
||||||
line = self.stdin.readline()
|
|
||||||
if not len(line):
|
|
||||||
self.lastcmd = ""
|
|
||||||
self.stdout.write('\n')
|
|
||||||
self.stdout.flush()
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
line = line.rstrip('\r\n')
|
self.stdout.write(continue_prompt)
|
||||||
buffer += '\n' + line
|
self.stdout.flush()
|
||||||
|
line = self.stdin.readline()
|
||||||
|
if not len(line):
|
||||||
|
self.lastcmd = ""
|
||||||
|
self.stdout.write('\n')
|
||||||
|
self.stdout.flush()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
line = line.rstrip('\r\n')
|
||||||
|
buffer += '\n' + line
|
||||||
save_stdout = sys.stdout
|
save_stdout = sys.stdout
|
||||||
save_stdin = sys.stdin
|
save_stdin = sys.stdin
|
||||||
save_displayhook = sys.displayhook
|
save_displayhook = sys.displayhook
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Disable tab completion in multiline mode of :mod:`pdb`
|
||||||
Loading…
Add table
Add a link
Reference in a new issue