##// END OF EJS Templates
Use module level getattr to emit deprecation
Matthias Bussonnier -
Show More
@@ -186,12 +186,12 b' AUTO_SUGGEST_BINDINGS = ['
186 186 # 2) prompt-toolkit checks if we are at the end of text, not end of line
187 187 # hence it does not work in multi-line mode of navigable provider
188 188 Binding(
189 auto_suggest.accept_in_vi_insert_mode,
189 auto_suggest.accept_or_jump_to_end,
190 190 ["end"],
191 191 "has_suggestion & default_buffer_focused & emacs_like_insert_mode",
192 192 ),
193 193 Binding(
194 auto_suggest.accept_in_vi_insert_mode,
194 auto_suggest.accept_or_jump_to_end,
195 195 ["c-e"],
196 196 "has_suggestion & default_buffer_focused & emacs_like_insert_mode",
197 197 ),
@@ -2,6 +2,7 b' import re'
2 2 import tokenize
3 3 from io import StringIO
4 4 from typing import Callable, List, Optional, Union, Generator, Tuple
5 import warnings
5 6
6 7 from prompt_toolkit.buffer import Buffer
7 8 from prompt_toolkit.key_binding import KeyPressEvent
@@ -192,7 +193,7 b' def accept_or_jump_to_end(event: KeyPressEvent):'
192 193 nc.end_of_line(event)
193 194
194 195
195 def accept_in_vi_insert_mode(event: KeyPressEvent):
196 def _deprected_accept_in_vi_insert_mode(event: KeyPressEvent):
196 197 """Accept autosuggestion or jump to end of line.
197 198
198 199 .. deprecated:: 8.12
@@ -381,3 +382,16 b' def swap_autosuggestion_down(event: KeyPressEvent):'
381 382 provider=provider,
382 383 direction_method=provider.down,
383 384 )
385
386
387 def __getattr__(key):
388 if key == "accept_in_vi_insert_mode":
389 warnings.warn(
390 "`accept_in_vi_insert_mode` is deprecated since IPython 8.12 and "
391 "renamed to `accept_or_jump_to_end`. Please update your configuration "
392 "accordingly",
393 DeprecationWarning,
394 stacklevel=2,
395 )
396 return _deprected_accept_in_vi_insert_mode
397 raise AttributeError
@@ -1,7 +1,7 b''
1 1 import pytest
2 2 from IPython.terminal.shortcuts.auto_suggest import (
3 3 accept,
4 accept_in_vi_insert_mode,
4 accept_or_jump_to_end,
5 5 accept_token,
6 6 accept_character,
7 7 accept_word,
@@ -22,6 +22,13 b' from prompt_toolkit.auto_suggest import AutoSuggestFromHistory'
22 22 from unittest.mock import patch, Mock
23 23
24 24
25 def test_deprected():
26 import IPython.terminal.shortcuts.auto_suggest as iptsa
27
28 with pytest.warns(DeprecationWarning, match=r"8\.12.+accept_or_jump_to_end"):
29 iptsa.accept_in_vi_insert_mode
30
31
25 32 def make_event(text, cursor, suggestion):
26 33 event = Mock()
27 34 event.current_buffer = Mock()
@@ -80,7 +87,7 b' def test_autosuggest_at_EOL(text, cursor, suggestion, called):'
80 87
81 88 event = make_event(text, cursor, suggestion)
82 89 event.current_buffer.insert_text = Mock()
83 accept_in_vi_insert_mode(event)
90 accept_or_jump_to_end(event)
84 91 if called:
85 92 event.current_buffer.insert_text.assert_called()
86 93 else:
General Comments 0
You need to be logged in to leave comments. Login now