gh-106734: Disable tab completion in multiline mode of pdb#106735
gh-106734: Disable tab completion in multiline mode of pdb#106735brandtbucher merged 7 commits intopython:mainfrom
Conversation
Lib/pdb.py
Outdated
| if (code := codeop.compile_command(line + '\n', '<stdin>', 'single')) is None: | ||
| # Multi-line mode | ||
| try: | ||
| import readline |
There was a problem hiding this comment.
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.
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.
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') |
|
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 <brandtbucher@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.