]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-106734: Disable tab completion in pdb's multiline mode (GH-106735)
authorTian Gao <gaogaotiantian@hotmail.com>
Tue, 12 Sep 2023 01:28:43 +0000 (18:28 -0700)
committerGitHub <noreply@github.com>
Tue, 12 Sep 2023 01:28:43 +0000 (18:28 -0700)
Lib/pdb.py
Misc/NEWS.d/next/Library/2023-07-14-01-47-39.gh-issue-106734.eMYSoz.rst [new file with mode: 0644]

index c31f608e6d9da56ff6c03e65851b027ad906e87b..e231d3d7eae47588376290e8199e14592015a27a 100755 (executable)
@@ -514,6 +514,22 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         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
@@ -521,28 +537,29 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         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
diff --git a/Misc/NEWS.d/next/Library/2023-07-14-01-47-39.gh-issue-106734.eMYSoz.rst b/Misc/NEWS.d/next/Library/2023-07-14-01-47-39.gh-issue-106734.eMYSoz.rst
new file mode 100644 (file)
index 0000000..37d2ab1
--- /dev/null
@@ -0,0 +1 @@
+Disable tab completion in multiline mode of :mod:`pdb`