Skip to content

Commit daa060f

Browse files
authored
Merge pull request #11979 from Carreau/ipdb-ptk
Add prompt toolkit 3 compatibility to ipdb
2 parents 4352b6b + f52ca01 commit daa060f

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

‎IPython/terminal/debugger.py‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from prompt_toolkit.enums import EditingMode
1818
from prompt_toolkit.formatted_text import PygmentsTokens
1919

20+
from prompt_toolkit import __version__ as ptk_version
21+
PTK3 = ptk_version.startswith('3.')
22+
2023

2124
class TerminalPdb(Pdb):
2225
"""Standalone IPython debugger."""
@@ -49,20 +52,23 @@ def get_prompt_tokens():
4952
& ~cursor_in_leading_ws
5053
))(display_completions_like_readline)
5154

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,
55+
options = dict(
56+
message=(lambda: PygmentsTokens(get_prompt_tokens())),
57+
editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
58+
key_bindings=kb,
59+
history=self.shell.debugger_history,
60+
completer=self._ptcomp,
61+
enable_history_search=True,
62+
mouse_support=self.shell.mouse_support,
63+
complete_style=self.shell.pt_complete_style,
64+
style=self.shell.style,
65+
color_depth=self.shell.color_depth,
6466
)
6567

68+
if not PTK3:
69+
options['inputhook'] = self.inputhook
70+
self.pt_app = PromptSession(**options)
71+
6672
def cmdloop(self, intro=None):
6773
"""Repeatedly issue a prompt, accept input, parse an initial prefix
6874
off the received input, and dispatch to action methods, passing them

0 commit comments

Comments
 (0)