summaryrefslogtreecommitdiffstats
path: root/Lib/pdb.py
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2023-11-14 12:22:25 (GMT)
committerGitHub <noreply@github.com>2023-11-14 12:22:25 (GMT)
commitf44d6ff6e0c9eeb0bb246a3dd8f99d40b7050054 (patch)
treeaf2ac4ad4871eaf0047b1e48f8e593a9993154f4 /Lib/pdb.py
parent324531df909721978446d504186738a33ab03fd5 (diff)
downloadcpython-f44d6ff6e0c9eeb0bb246a3dd8f99d40b7050054.zip
cpython-f44d6ff6e0c9eeb0bb246a3dd8f99d40b7050054.tar.gz
cpython-f44d6ff6e0c9eeb0bb246a3dd8f99d40b7050054.tar.bz2
gh-110944: Make pdb completion work for alias and convenience vars (GH-110945)
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-xLib/pdb.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index a4b02e0..ed78d74 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -238,7 +238,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
try:
import readline
# remove some common file name delimiters
- readline.set_completer_delims(' \t\n`@#$%^&*()=+[{]}\\|;:\'",<>?')
+ readline.set_completer_delims(' \t\n`@#%^&*()=+[{]}\\|;:\'",<>?')
except ImportError:
pass
self.allow_kbdint = False
@@ -686,6 +686,18 @@ class Pdb(bdb.Bdb, cmd.Cmd):
# Generic completion functions. Individual complete_foo methods can be
# assigned below to one of these functions.
+ def completenames(self, text, line, begidx, endidx):
+ # Overwrite completenames() of cmd so for the command completion,
+ # if no current command matches, check for expressions as well
+ commands = super().completenames(text, line, begidx, endidx)
+ for alias in self.aliases:
+ if alias.startswith(text):
+ commands.append(alias)
+ if commands:
+ return commands
+ else:
+ return self._complete_expression(text, line, begidx, endidx)
+
def _complete_location(self, text, line, begidx, endidx):
# Complete a file/module/function location for break/tbreak/clear.
if line.strip().endswith((':', ',')):
@@ -720,6 +732,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
# complete builtins, and they clutter the namespace quite heavily, so we
# leave them out.
ns = {**self.curframe.f_globals, **self.curframe_locals}
+ if text.startswith("$"):
+ # Complete convenience variables
+ conv_vars = self.curframe.f_globals.get('__pdb_convenience_variables', {})
+ return [f"${name}" for name in conv_vars if name.startswith(text[1:])]
if '.' in text:
# Walk an attribute chain up to the last part, similar to what
# rlcompleter does. This will bail if any of the parts are not