##// END OF EJS Templates
Use module level getattr to emit deprecation
Matthias Bussonnier -
Show More
@@ -186,12 +186,12 b' AUTO_SUGGEST_BINDINGS = ['
186 # 2) prompt-toolkit checks if we are at the end of text, not end of line
186 # 2) prompt-toolkit checks if we are at the end of text, not end of line
187 # hence it does not work in multi-line mode of navigable provider
187 # hence it does not work in multi-line mode of navigable provider
188 Binding(
188 Binding(
189 auto_suggest.accept_in_vi_insert_mode,
189 auto_suggest.accept_or_jump_to_end,
190 ["end"],
190 ["end"],
191 "has_suggestion & default_buffer_focused & emacs_like_insert_mode",
191 "has_suggestion & default_buffer_focused & emacs_like_insert_mode",
192 ),
192 ),
193 Binding(
193 Binding(
194 auto_suggest.accept_in_vi_insert_mode,
194 auto_suggest.accept_or_jump_to_end,
195 ["c-e"],
195 ["c-e"],
196 "has_suggestion & default_buffer_focused & emacs_like_insert_mode",
196 "has_suggestion & default_buffer_focused & emacs_like_insert_mode",
197 ),
197 ),
@@ -2,6 +2,7 b' import re'
2 import tokenize
2 import tokenize
3 from io import StringIO
3 from io import StringIO
4 from typing import Callable, List, Optional, Union, Generator, Tuple
4 from typing import Callable, List, Optional, Union, Generator, Tuple
5 import warnings
5
6
6 from prompt_toolkit.buffer import Buffer
7 from prompt_toolkit.buffer import Buffer
7 from prompt_toolkit.key_binding import KeyPressEvent
8 from prompt_toolkit.key_binding import KeyPressEvent
@@ -192,7 +193,7 b' def accept_or_jump_to_end(event: KeyPressEvent):'
192 nc.end_of_line(event)
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 """Accept autosuggestion or jump to end of line.
197 """Accept autosuggestion or jump to end of line.
197
198
198 .. deprecated:: 8.12
199 .. deprecated:: 8.12
@@ -381,3 +382,16 b' def swap_autosuggestion_down(event: KeyPressEvent):'
381 provider=provider,
382 provider=provider,
382 direction_method=provider.down,
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 import pytest
1 import pytest
2 from IPython.terminal.shortcuts.auto_suggest import (
2 from IPython.terminal.shortcuts.auto_suggest import (
3 accept,
3 accept,
4 accept_in_vi_insert_mode,
4 accept_or_jump_to_end,
5 accept_token,
5 accept_token,
6 accept_character,
6 accept_character,
7 accept_word,
7 accept_word,
@@ -22,6 +22,13 b' from prompt_toolkit.auto_suggest import AutoSuggestFromHistory'
22 from unittest.mock import patch, Mock
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 def make_event(text, cursor, suggestion):
32 def make_event(text, cursor, suggestion):
26 event = Mock()
33 event = Mock()
27 event.current_buffer = Mock()
34 event.current_buffer = Mock()
@@ -80,7 +87,7 b' def test_autosuggest_at_EOL(text, cursor, suggestion, called):'
80
87
81 event = make_event(text, cursor, suggestion)
88 event = make_event(text, cursor, suggestion)
82 event.current_buffer.insert_text = Mock()
89 event.current_buffer.insert_text = Mock()
83 accept_in_vi_insert_mode(event)
90 accept_or_jump_to_end(event)
84 if called:
91 if called:
85 event.current_buffer.insert_text.assert_called()
92 event.current_buffer.insert_text.assert_called()
86 else:
93 else:
General Comments 0
You need to be logged in to leave comments. Login now