-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Conversation
Lib/pdb.py
Outdated
try: | ||
if (code := codeop.compile_command(line + '\n', '<stdin>', 'single')) is None: | ||
# Multi-line mode | ||
try: | ||
import readline |
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.
Maybe it's worth doing this just once at module level? I see we're already trying to import readline
up in Pdb.__init__
.
Lib/pdb.py
Outdated
try: | ||
import readline | ||
# Disable tab-completion temporarily | ||
readline.parse_and_bind('tab: self-insert') |
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.
It seems like the Cmd
base class is a bit more careful about moves like this. For example, maybe we should only do this if self.use_rawinput and self.completekey == "tab" and readline.get_completer() is self.complete
? That way we don't change the global readline
state in an unexpected way during debugging.
What do you think?
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.
Yeah we should protect this with use_rawinput
and completekey
, however, I'm not sure if checking the get_completer()
is necessary. The completer should always be self.complete
. In any case, we should not trigger the completer function in multiline mode - tab should always input tab.
As for importing readline globally, cmd
does it twice in the code - I think it's because readline
is only available on some systems. This is more explicit than having a readline is None
check in the function.
I can move the readline reverting part into the mutiline if statement - so we can avoid changing the readline states in exec()
- even though it's hard to imagine having useful code there to use readline
.
Lib/pdb.py
Outdated
if readline: | ||
readline.parse_and_bind('tab: complete') |
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.
Ditto.
So I switched to a context based solution - a couple of days ago a context manager was included in pdb so we already had that. Now the input part is contained in a "disable tab" context which checks for |
Co-authored-by: Brandt Bucher <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.