From dd89efe34477ca8e6de7f0ccdeb922e077ce4261 2023-01-28 23:24:54
From: krassowski <5832902+krassowski@users.noreply.github.com>
Date: 2023-01-28 23:24:54
Subject: [PATCH] Fix disabling auto-suggestions

---

diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py
index c61024c..b5fc148 100644
--- a/IPython/terminal/interactiveshell.py
+++ b/IPython/terminal/interactiveshell.py
@@ -147,10 +147,6 @@ class PtkHistoryAdapter(History):
 
     """
 
-    auto_suggest: UnionType[
-        AutoSuggestFromHistory, NavigableAutoSuggestFromHistory, None
-    ]
-
     def __init__(self, shell):
         super().__init__()
         self.shell = shell
@@ -193,6 +189,9 @@ class TerminalInteractiveShell(InteractiveShell):
                             ).tag(config=True)
 
     pt_app: UnionType[PromptSession, None] = None
+    auto_suggest: UnionType[
+        AutoSuggestFromHistory, NavigableAutoSuggestFromHistory, None
+    ] = None
     debugger_history = None
 
     debugger_history_file = Unicode(
@@ -685,7 +684,6 @@ class TerminalInteractiveShell(InteractiveShell):
 
     def __init__(self, *args, **kwargs) -> None:
         super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
-        self.auto_suggest = None
         self._set_autosuggestions(self.autosuggestions_provider)
         self.init_prompt_toolkit_cli()
         self.init_term_title()
diff --git a/IPython/terminal/tests/test_interactivshell.py b/IPython/terminal/tests/test_interactivshell.py
index 68dbe37..01008d7 100644
--- a/IPython/terminal/tests/test_interactivshell.py
+++ b/IPython/terminal/tests/test_interactivshell.py
@@ -7,11 +7,25 @@ import sys
 import unittest
 import os
 
+from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
+
 from IPython.core.inputtransformer import InputTransformer
 from IPython.testing import tools as tt
 from IPython.utils.capture import capture_output
 
 from IPython.terminal.ptutils import _elide, _adjust_completion_text_based_on_context
+from IPython.terminal.shortcuts.auto_suggest import NavigableAutoSuggestFromHistory
+
+
+class TestAutoSuggest(unittest.TestCase):
+    def test_changing_provider(self):
+        ip = get_ipython()
+        ip.autosuggestions_provider = None
+        self.assertEqual(ip.auto_suggest, None)
+        ip.autosuggestions_provider = "AutoSuggestFromHistory"
+        self.assertIsInstance(ip.auto_suggest, AutoSuggestFromHistory)
+        ip.autosuggestions_provider = "NavigableAutoSuggestFromHistory"
+        self.assertIsInstance(ip.auto_suggest, NavigableAutoSuggestFromHistory)
 
 
 class TestElide(unittest.TestCase):
@@ -24,10 +38,10 @@ class TestElide(unittest.TestCase):
         )
 
         test_string = os.sep.join(["", 10 * "a", 10 * "b", 10 * "c", ""])
-        expect_stirng = (
+        expect_string = (
             os.sep + "a" + "\N{HORIZONTAL ELLIPSIS}" + "b" + os.sep + 10 * "c"
         )
-        self.assertEqual(_elide(test_string, ""), expect_stirng)
+        self.assertEqual(_elide(test_string, ""), expect_string)
 
     def test_elide_typed_normal(self):
         self.assertEqual(