From 046284bdbf3f848d78d6c40dfca84460e9d2665a 2017-01-31 13:50:27 From: Min RK Date: 2017-01-31 13:50:27 Subject: [PATCH] Backport PR #10223: Fix error tab completing in the debugger I think I broke this in 5.2. Closes gh-10222 --- diff --git a/IPython/terminal/debugger.py b/IPython/terminal/debugger.py index 9c8997d..ffbd12f 100644 --- a/IPython/terminal/debugger.py +++ b/IPython/terminal/debugger.py @@ -20,6 +20,9 @@ class TerminalPdb(Pdb): def get_prompt_tokens(cli): return [(Token.Prompt, self.prompt)] + def patch_stdout(**kwargs): + return self.pt_cli.patch_stdout_context(**kwargs) + if self._ptcomp is None: compl = IPCompleter(shell=self.shell, namespace={}, @@ -27,7 +30,7 @@ class TerminalPdb(Pdb): use_readline=False, parent=self.shell, ) - self._ptcomp = IPythonPTCompleter(compl) + self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout) self._pt_app = create_prompt_application( editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 3c6e4e2..7f87fe9 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -237,11 +237,15 @@ class TerminalInteractiveShell(InteractiveShell): editing_mode = getattr(EditingMode, self.editing_mode.upper()) + def patch_stdout(**kwargs): + return self.pt_cli.patch_stdout_context(**kwargs) + self._pt_app = create_prompt_application( editing_mode=editing_mode, key_bindings_registry=kbmanager.registry, history=history, - completer=IPythonPTCompleter(shell=self), + completer=IPythonPTCompleter(shell=self, + patch_stdout=patch_stdout), enable_history_search=True, style=style, mouse_support=self.mouse_support, diff --git a/IPython/terminal/ptutils.py b/IPython/terminal/ptutils.py index 152899d..c9ff705 100644 --- a/IPython/terminal/ptutils.py +++ b/IPython/terminal/ptutils.py @@ -22,11 +22,14 @@ import pygments.lexers as pygments_lexers class IPythonPTCompleter(Completer): """Adaptor to provide IPython completions to prompt_toolkit""" - def __init__(self, ipy_completer=None, shell=None): + def __init__(self, ipy_completer=None, shell=None, patch_stdout=None): if shell is None and ipy_completer is None: raise TypeError("Please pass shell=an InteractiveShell instance.") self._ipy_completer = ipy_completer self.shell = shell + if patch_stdout is None: + raise TypeError("Please pass patch_stdout") + self.patch_stdout = patch_stdout @property def ipy_completer(self): @@ -42,7 +45,7 @@ class IPythonPTCompleter(Completer): # Some bits of our completion system may print stuff (e.g. if a module # is imported). This context manager ensures that doesn't interfere with # the prompt. - with self.shell.pt_cli.patch_stdout_context(): + with self.patch_stdout(): used, matches = self.ipy_completer.complete( line_buffer=document.current_line, cursor_pos=document.cursor_position_col