mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-131123: Support completion in pdb
for convenience variable attributes (#131124)
This commit is contained in:
parent
17d06aeb54
commit
b52866953a
3 changed files with 28 additions and 5 deletions
13
Lib/pdb.py
13
Lib/pdb.py
|
@ -975,17 +975,16 @@ 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.f_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
|
||||
# simple attribute access, which is what we want.
|
||||
dotted = text.split('.')
|
||||
try:
|
||||
obj = ns[dotted[0]]
|
||||
if dotted[0].startswith('$'):
|
||||
obj = self.curframe.f_globals['__pdb_convenience_variables'][dotted[0][1:]]
|
||||
else:
|
||||
obj = ns[dotted[0]]
|
||||
for part in dotted[1:-1]:
|
||||
obj = getattr(obj, part)
|
||||
except (KeyError, AttributeError):
|
||||
|
@ -993,6 +992,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
prefix = '.'.join(dotted[:-1]) + '.'
|
||||
return [prefix + n for n in dir(obj) if n.startswith(dotted[-1])]
|
||||
else:
|
||||
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:])]
|
||||
# Complete a simple name.
|
||||
return [n for n in ns.keys() if n.startswith(text)]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue