-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-110944: Make pdb completion work for alias and convenience vars #110945
Changes from all commits
061eeb8
4f23a98
3771b93
f023848
b1b46b1
fbc6f23
b655b94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,7 +238,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, | |
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 @@ def set_convenience_variable(self, frame, name, value): | |
# Generic completion functions. Individual complete_foo methods can be | ||
# assigned below to one of these functions. | ||
|
||
def completenames(self, text, line, begidx, endidx): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is overwritting the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think adding a test that covers this would be better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you can (easily) set up a readline test to really trigger the "complete" feature of readline. Even |
||
# 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 @@ def _complete_expression(self, text, line, begidx, endidx): | |
# 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support alias and convenience vars for :mod:`pdb` completion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no tests in this PR.
What could this change break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no test for completion, presumably because it's not easy to test. It would change the behavior when the user tries to do a complete (hit
<tab>
in most cases) and there's a$
in the line. In that case,$
would be not considered as a delimiter (the text to be completed would include$
). I can't think of any real cases where this matters. Actually, I can't think of a case where the user uses$
in their pdb commands (other than using convenience variable of course).