prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Incompatibility with prompt_toolkit v3.0.0
  I noticed the following error today:
  
  ```
      def pt_init(self):
          def get_prompt_tokens():
              return [(Token.Prompt, self.prompt)]
  
          if self._ptcomp is None:
              compl = IPCompleter(shell=self.shell,
                                          namespace={},
                                          global_namespace={},
                                          parent=self.shell,
                                         )
              self._ptcomp = IPythonPTCompleter(compl)
  
          kb = KeyBindings()
          supports_suspend = Condition(lambda: hasattr(signal, 'SIGTSTP'))
          kb.add('c-z', filter=supports_suspend)(suspend_to_bg)
  
          if self.shell.display_completions == 'readlinelike':
              kb.add('tab', filter=(has_focus(DEFAULT_BUFFER)
                                    & ~has_selection
                                    & vi_insert_mode | emacs_insert_mode
                                    & ~cursor_in_leading_ws
                                ))(display_completions_like_readline)
  
          self.pt_app = PromptSession(
                              message=(lambda: PygmentsTokens(get_prompt_tokens())),
                              editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
                              key_bindings=kb,
                              history=self.shell.debugger_history,
                              completer=self._ptcomp,
                              enable_history_search=True,
                              mouse_support=self.shell.mouse_support,
                              complete_style=self.shell.pt_complete_style,
                              style=self.shell.style,
                              inputhook=self.shell.inputhook,
  >                           color_depth=self.shell.color_depth,
          )
  E       TypeError: __init__() got an unexpected keyword argument 'inputhook'
  ```
  `PromptSession` in `prompt_toolkit` v3 does not have an `inputhook` parameter - https://github.com/prompt-toolkit/python-prompt-toolkit/blob/4cbbf8b9db1cb11caa1d72f4200c5cbc48bfd384/prompt_toolkit/shortcuts/prompt.py#L340-L383
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `IPython/terminal/debugger.py`
  Content:
  ```
  1 import signal
  2 import sys
  3 
  4 from IPython.core.debugger import Pdb
  5 
  6 from IPython.core.completer import IPCompleter
  7 from .ptutils import IPythonPTCompleter
  8 from .shortcuts import suspend_to_bg, cursor_in_leading_ws
  9 
  10 from prompt_toolkit.enums import DEFAULT_BUFFER
  11 from prompt_toolkit.filters import (Condition, has_focus, has_selection,
  12     vi_insert_mode, emacs_insert_mode)
  13 from prompt_toolkit.key_binding import KeyBindings
  14 from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
  15 from pygments.token import Token
  16 from prompt_toolkit.shortcuts.prompt import PromptSession
  17 from prompt_toolkit.enums import EditingMode
  18 from prompt_toolkit.formatted_text import PygmentsTokens
  19 
  20 
  21 class TerminalPdb(Pdb):
  22     """Standalone IPython debugger."""
  23 
  24     def __init__(self, *args, **kwargs):
  25         Pdb.__init__(self, *args, **kwargs)
  26         self._ptcomp = None
  27         self.pt_init()
  28 
  29     def pt_init(self):
  30         def get_prompt_tokens():
  31             return [(Token.Prompt, self.prompt)]
  32 
  33         if self._ptcomp is None:
  34             compl = IPCompleter(shell=self.shell,
  35                                         namespace={},
  36                                         global_namespace={},
  37                                         parent=self.shell,
  38                                        )
  39             self._ptcomp = IPythonPTCompleter(compl)
  40 
  41         kb = KeyBindings()
  42         supports_suspend = Condition(lambda: hasattr(signal, 'SIGTSTP'))
  43         kb.add('c-z', filter=supports_suspend)(suspend_to_bg)
  44 
  45         if self.shell.display_completions == 'readlinelike':
  46             kb.add('tab', filter=(has_focus(DEFAULT_BUFFER)
  47                                   & ~has_selection
  48                                   & vi_insert_mode | emacs_insert_mode
  49                                   & ~cursor_in_leading_ws
  50                               ))(display_completions_like_readline)
  51 
  52         self.pt_app = PromptSession(
  53                             message=(lambda: PygmentsTokens(get_prompt_tokens())),
  54                             editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
  55                             key_bindings=kb,
  56                             history=self.shell.debugger_history,
  57                             completer=self._ptcomp,
  58                             enable_history_search=True,
  59                             mouse_support=self.shell.mouse_support,
  60                             complete_style=self.shell.pt_complete_style,
  61                             style=self.shell.style,
  62                             inputhook=self.shell.inputhook,
  63                             color_depth=self.shell.color_depth,
  64         )
  65 
  66     def cmdloop(self, intro=None):
  67         """Repeatedly issue a prompt, accept input, parse an initial prefix
  68         off the received input, and dispatch to action methods, passing them
  69         the remainder of the line as argument.
  70 
  71         override the same methods from cmd.Cmd to provide prompt toolkit replacement.
  72         """
  73         if not self.use_rawinput:
  74             raise ValueError('Sorry ipdb does not support use_rawinput=False')
  75 
  76         self.preloop()
  77 
  78         try:
  79             if intro is not None:
  80                 self.intro = intro
  81             if self.intro:
  82                 self.stdout.write(str(self.intro)+"\n")
  83             stop = None
  84             while not stop:
  85                 if self.cmdqueue:
  86                     line = self.cmdqueue.pop(0)
  87                 else:
  88                     self._ptcomp.ipy_completer.namespace = self.curframe_locals
  89                     self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
  90                     try:
  91                         line = self.pt_app.prompt() # reset_current_buffer=True)
  92                     except EOFError:
  93                         line = 'EOF'
  94                 line = self.precmd(line)
  95                 stop = self.onecmd(line)
  96                 stop = self.postcmd(stop, line)
  97             self.postloop()
  98         except Exception:
  99             raise
  100 
  101 
  102 def set_trace(frame=None):
  103     """
  104     Start debugging from `frame`.
  105 
  106     If frame is not specified, debugging starts from caller's frame.
  107     """
  108     TerminalPdb().set_trace(frame or sys._getframe().f_back)
  109 
  110 
  111 if __name__ == '__main__':
  112     import pdb
  113     # IPython.core.debugger.Pdb.trace_dispatch shall not catch
  114     # bdb.BdbQuit. When started through __main__ and an exception
  115     # happened after hitting "c", this is needed in order to
  116     # be able to quit the debugging session (see #9950).
  117     old_trace_dispatch = pdb.Pdb.trace_dispatch
  118     pdb.Pdb = TerminalPdb
  119     pdb.Pdb.trace_dispatch = old_trace_dispatch
  120     pdb.main()
  121
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/IPython/terminal/debugger.py b/IPython/terminal/debugger.py
  --- a/IPython/terminal/debugger.py
  +++ b/IPython/terminal/debugger.py
  @@ -17,6 +17,9 @@
   from prompt_toolkit.enums import EditingMode
   from prompt_toolkit.formatted_text import PygmentsTokens
   
  +from prompt_toolkit import __version__ as ptk_version
  +PTK3 = ptk_version.startswith('3.')
  +
   
   class TerminalPdb(Pdb):
       """Standalone IPython debugger."""
  @@ -49,20 +52,23 @@
                                     & ~cursor_in_leading_ws
                                 ))(display_completions_like_readline)
   
  -        self.pt_app = PromptSession(
  -                            message=(lambda: PygmentsTokens(get_prompt_tokens())),
  -                            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
  -                            key_bindings=kb,
  -                            history=self.shell.debugger_history,
  -                            completer=self._ptcomp,
  -                            enable_history_search=True,
  -                            mouse_support=self.shell.mouse_support,
  -                            complete_style=self.shell.pt_complete_style,
  -                            style=self.shell.style,
  -                            inputhook=self.shell.inputhook,
  -                            color_depth=self.shell.color_depth,
  +        options = dict(
  +            message=(lambda: PygmentsTokens(get_prompt_tokens())),
  +            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
  +            key_bindings=kb,
  +            history=self.shell.debugger_history,
  +            completer=self._ptcomp,
  +            enable_history_search=True,
  +            mouse_support=self.shell.mouse_support,
  +            complete_style=self.shell.pt_complete_style,
  +            style=self.shell.style,
  +            color_depth=self.shell.color_depth,
           )
   
  +        if not PTK3:
  +            options['inputhook'] = self.inputhook
  +        self.pt_app = PromptSession(**options)
  +
       def cmdloop(self, intro=None):
           """Repeatedly issue a prompt, accept input, parse an initial prefix
           off the received input, and dispatch to action methods, passing them
  
verification_info: {"golden_diff": "diff --git a/IPython/terminal/debugger.py b/IPython/terminal/debugger.py\n--- a/IPython/terminal/debugger.py\n+++ b/IPython/terminal/debugger.py\n@@ -17,6 +17,9 @@\n from prompt_toolkit.enums import EditingMode\n from prompt_toolkit.formatted_text import PygmentsTokens\n \n+from prompt_toolkit import __version__ as ptk_version\n+PTK3 = ptk_version.startswith('3.')\n+\n \n class TerminalPdb(Pdb):\n     \"\"\"Standalone IPython debugger.\"\"\"\n@@ -49,20 +52,23 @@\n                                   & ~cursor_in_leading_ws\n                               ))(display_completions_like_readline)\n \n-        self.pt_app = PromptSession(\n-                            message=(lambda: PygmentsTokens(get_prompt_tokens())),\n-                            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),\n-                            key_bindings=kb,\n-                            history=self.shell.debugger_history,\n-                            completer=self._ptcomp,\n-                            enable_history_search=True,\n-                            mouse_support=self.shell.mouse_support,\n-                            complete_style=self.shell.pt_complete_style,\n-                            style=self.shell.style,\n-                            inputhook=self.shell.inputhook,\n-                            color_depth=self.shell.color_depth,\n+        options = dict(\n+            message=(lambda: PygmentsTokens(get_prompt_tokens())),\n+            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),\n+            key_bindings=kb,\n+            history=self.shell.debugger_history,\n+            completer=self._ptcomp,\n+            enable_history_search=True,\n+            mouse_support=self.shell.mouse_support,\n+            complete_style=self.shell.pt_complete_style,\n+            style=self.shell.style,\n+            color_depth=self.shell.color_depth,\n         )\n \n+        if not PTK3:\n+            options['inputhook'] = self.inputhook\n+        self.pt_app = PromptSession(**options)\n+\n     def cmdloop(self, intro=None):\n         \"\"\"Repeatedly issue a prompt, accept input, parse an initial prefix\n         off the received input, and dispatch to action methods, passing them\n", "issue": "Incompatibility with prompt_toolkit v3.0.0\nI noticed the following error today:\r\n\r\n```\r\n    def pt_init(self):\r\n        def get_prompt_tokens():\r\n            return [(Token.Prompt, self.prompt)]\r\n\r\n        if self._ptcomp is None:\r\n            compl = IPCompleter(shell=self.shell,\r\n                                        namespace={},\r\n                                        global_namespace={},\r\n                                        parent=self.shell,\r\n                                       )\r\n            self._ptcomp = IPythonPTCompleter(compl)\r\n\r\n        kb = KeyBindings()\r\n        supports_suspend = Condition(lambda: hasattr(signal, 'SIGTSTP'))\r\n        kb.add('c-z', filter=supports_suspend)(suspend_to_bg)\r\n\r\n        if self.shell.display_completions == 'readlinelike':\r\n            kb.add('tab', filter=(has_focus(DEFAULT_BUFFER)\r\n                                  & ~has_selection\r\n                                  & vi_insert_mode | emacs_insert_mode\r\n                                  & ~cursor_in_leading_ws\r\n                              ))(display_completions_like_readline)\r\n\r\n        self.pt_app = PromptSession(\r\n                            message=(lambda: PygmentsTokens(get_prompt_tokens())),\r\n                            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),\r\n                            key_bindings=kb,\r\n                            history=self.shell.debugger_history,\r\n                            completer=self._ptcomp,\r\n                            enable_history_search=True,\r\n                            mouse_support=self.shell.mouse_support,\r\n                            complete_style=self.shell.pt_complete_style,\r\n                            style=self.shell.style,\r\n                            inputhook=self.shell.inputhook,\r\n>                           color_depth=self.shell.color_depth,\r\n        )\r\nE       TypeError: __init__() got an unexpected keyword argument 'inputhook'\r\n```\r\n`PromptSession` in `prompt_toolkit` v3 does not have an `inputhook` parameter - https://github.com/prompt-toolkit/python-prompt-toolkit/blob/4cbbf8b9db1cb11caa1d72f4200c5cbc48bfd384/prompt_toolkit/shortcuts/prompt.py#L340-L383\n", "before_files": [{"content": "import signal\nimport sys\n\nfrom IPython.core.debugger import Pdb\n\nfrom IPython.core.completer import IPCompleter\nfrom .ptutils import IPythonPTCompleter\nfrom .shortcuts import suspend_to_bg, cursor_in_leading_ws\n\nfrom prompt_toolkit.enums import DEFAULT_BUFFER\nfrom prompt_toolkit.filters import (Condition, has_focus, has_selection,\n    vi_insert_mode, emacs_insert_mode)\nfrom prompt_toolkit.key_binding import KeyBindings\nfrom prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline\nfrom pygments.token import Token\nfrom prompt_toolkit.shortcuts.prompt import PromptSession\nfrom prompt_toolkit.enums import EditingMode\nfrom prompt_toolkit.formatted_text import PygmentsTokens\n\n\nclass TerminalPdb(Pdb):\n    \"\"\"Standalone IPython debugger.\"\"\"\n\n    def __init__(self, *args, **kwargs):\n        Pdb.__init__(self, *args, **kwargs)\n        self._ptcomp = None\n        self.pt_init()\n\n    def pt_init(self):\n        def get_prompt_tokens():\n            return [(Token.Prompt, self.prompt)]\n\n        if self._ptcomp is None:\n            compl = IPCompleter(shell=self.shell,\n                                        namespace={},\n                                        global_namespace={},\n                                        parent=self.shell,\n                                       )\n            self._ptcomp = IPythonPTCompleter(compl)\n\n        kb = KeyBindings()\n        supports_suspend = Condition(lambda: hasattr(signal, 'SIGTSTP'))\n        kb.add('c-z', filter=supports_suspend)(suspend_to_bg)\n\n        if self.shell.display_completions == 'readlinelike':\n            kb.add('tab', filter=(has_focus(DEFAULT_BUFFER)\n                                  & ~has_selection\n                                  & vi_insert_mode | emacs_insert_mode\n                                  & ~cursor_in_leading_ws\n                              ))(display_completions_like_readline)\n\n        self.pt_app = PromptSession(\n                            message=(lambda: PygmentsTokens(get_prompt_tokens())),\n                            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),\n                            key_bindings=kb,\n                            history=self.shell.debugger_history,\n                            completer=self._ptcomp,\n                            enable_history_search=True,\n                            mouse_support=self.shell.mouse_support,\n                            complete_style=self.shell.pt_complete_style,\n                            style=self.shell.style,\n                            inputhook=self.shell.inputhook,\n                            color_depth=self.shell.color_depth,\n        )\n\n    def cmdloop(self, intro=None):\n        \"\"\"Repeatedly issue a prompt, accept input, parse an initial prefix\n        off the received input, and dispatch to action methods, passing them\n        the remainder of the line as argument.\n\n        override the same methods from cmd.Cmd to provide prompt toolkit replacement.\n        \"\"\"\n        if not self.use_rawinput:\n            raise ValueError('Sorry ipdb does not support use_rawinput=False')\n\n        self.preloop()\n\n        try:\n            if intro is not None:\n                self.intro = intro\n            if self.intro:\n                self.stdout.write(str(self.intro)+\"\\n\")\n            stop = None\n            while not stop:\n                if self.cmdqueue:\n                    line = self.cmdqueue.pop(0)\n                else:\n                    self._ptcomp.ipy_completer.namespace = self.curframe_locals\n                    self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals\n                    try:\n                        line = self.pt_app.prompt() # reset_current_buffer=True)\n                    except EOFError:\n                        line = 'EOF'\n                line = self.precmd(line)\n                stop = self.onecmd(line)\n                stop = self.postcmd(stop, line)\n            self.postloop()\n        except Exception:\n            raise\n\n\ndef set_trace(frame=None):\n    \"\"\"\n    Start debugging from `frame`.\n\n    If frame is not specified, debugging starts from caller's frame.\n    \"\"\"\n    TerminalPdb().set_trace(frame or sys._getframe().f_back)\n\n\nif __name__ == '__main__':\n    import pdb\n    # IPython.core.debugger.Pdb.trace_dispatch shall not catch\n    # bdb.BdbQuit. When started through __main__ and an exception\n    # happened after hitting \"c\", this is needed in order to\n    # be able to quit the debugging session (see #9950).\n    old_trace_dispatch = pdb.Pdb.trace_dispatch\n    pdb.Pdb = TerminalPdb\n    pdb.Pdb.trace_dispatch = old_trace_dispatch\n    pdb.main()\n", "path": "IPython/terminal/debugger.py"}], "after_files": [{"content": "import signal\nimport sys\n\nfrom IPython.core.debugger import Pdb\n\nfrom IPython.core.completer import IPCompleter\nfrom .ptutils import IPythonPTCompleter\nfrom .shortcuts import suspend_to_bg, cursor_in_leading_ws\n\nfrom prompt_toolkit.enums import DEFAULT_BUFFER\nfrom prompt_toolkit.filters import (Condition, has_focus, has_selection,\n    vi_insert_mode, emacs_insert_mode)\nfrom prompt_toolkit.key_binding import KeyBindings\nfrom prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline\nfrom pygments.token import Token\nfrom prompt_toolkit.shortcuts.prompt import PromptSession\nfrom prompt_toolkit.enums import EditingMode\nfrom prompt_toolkit.formatted_text import PygmentsTokens\n\nfrom prompt_toolkit import __version__ as ptk_version\nPTK3 = ptk_version.startswith('3.')\n\n\nclass TerminalPdb(Pdb):\n    \"\"\"Standalone IPython debugger.\"\"\"\n\n    def __init__(self, *args, **kwargs):\n        Pdb.__init__(self, *args, **kwargs)\n        self._ptcomp = None\n        self.pt_init()\n\n    def pt_init(self):\n        def get_prompt_tokens():\n            return [(Token.Prompt, self.prompt)]\n\n        if self._ptcomp is None:\n            compl = IPCompleter(shell=self.shell,\n                                        namespace={},\n                                        global_namespace={},\n                                        parent=self.shell,\n                                       )\n            self._ptcomp = IPythonPTCompleter(compl)\n\n        kb = KeyBindings()\n        supports_suspend = Condition(lambda: hasattr(signal, 'SIGTSTP'))\n        kb.add('c-z', filter=supports_suspend)(suspend_to_bg)\n\n        if self.shell.display_completions == 'readlinelike':\n            kb.add('tab', filter=(has_focus(DEFAULT_BUFFER)\n                                  & ~has_selection\n                                  & vi_insert_mode | emacs_insert_mode\n                                  & ~cursor_in_leading_ws\n                              ))(display_completions_like_readline)\n\n        options = dict(\n            message=(lambda: PygmentsTokens(get_prompt_tokens())),\n            editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),\n            key_bindings=kb,\n            history=self.shell.debugger_history,\n            completer=self._ptcomp,\n            enable_history_search=True,\n            mouse_support=self.shell.mouse_support,\n            complete_style=self.shell.pt_complete_style,\n            style=self.shell.style,\n            color_depth=self.shell.color_depth,\n        )\n\n        if not PTK3:\n            options['inputhook'] = self.inputhook\n        self.pt_app = PromptSession(**options)\n\n    def cmdloop(self, intro=None):\n        \"\"\"Repeatedly issue a prompt, accept input, parse an initial prefix\n        off the received input, and dispatch to action methods, passing them\n        the remainder of the line as argument.\n\n        override the same methods from cmd.Cmd to provide prompt toolkit replacement.\n        \"\"\"\n        if not self.use_rawinput:\n            raise ValueError('Sorry ipdb does not support use_rawinput=False')\n\n        self.preloop()\n\n        try:\n            if intro is not None:\n                self.intro = intro\n            if self.intro:\n                self.stdout.write(str(self.intro)+\"\\n\")\n            stop = None\n            while not stop:\n                if self.cmdqueue:\n                    line = self.cmdqueue.pop(0)\n                else:\n                    self._ptcomp.ipy_completer.namespace = self.curframe_locals\n                    self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals\n                    try:\n                        line = self.pt_app.prompt() # reset_current_buffer=True)\n                    except EOFError:\n                        line = 'EOF'\n                line = self.precmd(line)\n                stop = self.onecmd(line)\n                stop = self.postcmd(stop, line)\n            self.postloop()\n        except Exception:\n            raise\n\n\ndef set_trace(frame=None):\n    \"\"\"\n    Start debugging from `frame`.\n\n    If frame is not specified, debugging starts from caller's frame.\n    \"\"\"\n    TerminalPdb().set_trace(frame or sys._getframe().f_back)\n\n\nif __name__ == '__main__':\n    import pdb\n    # IPython.core.debugger.Pdb.trace_dispatch shall not catch\n    # bdb.BdbQuit. When started through __main__ and an exception\n    # happened after hitting \"c\", this is needed in order to\n    # be able to quit the debugging session (see #9950).\n    old_trace_dispatch = pdb.Pdb.trace_dispatch\n    pdb.Pdb = TerminalPdb\n    pdb.Pdb.trace_dispatch = old_trace_dispatch\n    pdb.main()\n", "path": "IPython/terminal/debugger.py"}]}