Skip to content

gh-106734: Disable tab completion in multiline mode of pdb #106735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,35 +514,52 @@ def displayhook(self, obj):
if obj is not None:
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):
if line[:1] == '!': line = line[1:].strip()
locals = self.curframe_locals
globals = self.curframe.f_globals
try:
if (code := codeop.compile_command(line + '\n', '<stdin>', 'single')) is None:
# Multi-line mode
buffer = line
continue_prompt = "... "
while (code := codeop.compile_command(buffer, '<stdin>', 'single')) is None:
if self.use_rawinput:
try:
line = input(continue_prompt)
except (EOFError, KeyboardInterrupt):
self.lastcmd = ""
print('\n')
return
else:
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
with self._disable_tab_completion():
buffer = line
continue_prompt = "... "
while (code := codeop.compile_command(buffer, '<stdin>', 'single')) is None:
if self.use_rawinput:
try:
line = input(continue_prompt)
except (EOFError, KeyboardInterrupt):
self.lastcmd = ""
print('\n')
return
else:
line = line.rstrip('\r\n')
buffer += '\n' + line
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:
line = line.rstrip('\r\n')
buffer += '\n' + line
save_stdout = sys.stdout
save_stdin = sys.stdin
save_displayhook = sys.displayhook
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable tab completion in multiline mode of :mod:`pdb`