diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index f1f4444..7387822 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -238,7 +238,7 @@ class TerminalInteractiveShell(InteractiveShell): editing_mode=editing_mode, key_bindings_registry=kbmanager.registry, history=history, - completer=IPythonPTCompleter(self), + completer=IPythonPTCompleter(shell=self), enable_history_search=True, style=style, mouse_support=self.mouse_support, diff --git a/IPython/terminal/ptutils.py b/IPython/terminal/ptutils.py index 156181e..84515e1 100644 --- a/IPython/terminal/ptutils.py +++ b/IPython/terminal/ptutils.py @@ -1,3 +1,12 @@ +"""prompt-toolkit utilities + +Everything in this module is a private API, +not to be used outside IPython. +""" + +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + import unicodedata from wcwidth import wcwidth @@ -13,15 +22,18 @@ import pygments.lexers as pygments_lexers class IPythonPTCompleter(Completer): """Adaptor to provide IPython completions to prompt_toolkit""" - def __init__(self, shell): - if isinstance(shell, IPCompleter): - raise TypeError("IPythonPTCompleter expects an InteractiveShell" - " instance in IPython 5.1, not a Completer") + def __init__(self, ipy_completer=None, shell=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 @property def ipy_completer(self): - return self.shell.Completer + if self._ipy_completer: + return self._ipy_completer + else: + return self.shell.Completer def get_completions(self, document, complete_event): if not document.current_line.strip():