Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eccd2db

Browse files
committed
Use module level getattr to emit deprecation
1 parent d812428 commit eccd2db

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

IPython/terminal/shortcuts/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ def create_identifier(handler: Callable):
186186
# 2) prompt-toolkit checks if we are at the end of text, not end of line
187187
# hence it does not work in multi-line mode of navigable provider
188188
Binding(
189-
auto_suggest.accept_in_vi_insert_mode,
189+
auto_suggest.accept_or_jump_to_end,
190190
["end"],
191191
"has_suggestion & default_buffer_focused & emacs_like_insert_mode",
192192
),
193193
Binding(
194-
auto_suggest.accept_in_vi_insert_mode,
194+
auto_suggest.accept_or_jump_to_end,
195195
["c-e"],
196196
"has_suggestion & default_buffer_focused & emacs_like_insert_mode",
197197
),

IPython/terminal/shortcuts/auto_suggest.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import tokenize
33
from io import StringIO
44
from typing import Callable, List, Optional, Union, Generator, Tuple
5+
import warnings
56

67
from prompt_toolkit.buffer import Buffer
78
from prompt_toolkit.key_binding import KeyPressEvent
@@ -192,7 +193,7 @@ def accept_or_jump_to_end(event: KeyPressEvent):
192193
nc.end_of_line(event)
193194

194195

195-
def accept_in_vi_insert_mode(event: KeyPressEvent):
196+
def _deprected_accept_in_vi_insert_mode(event: KeyPressEvent):
196197
"""Accept autosuggestion or jump to end of line.
197198
198199
.. deprecated:: 8.12
@@ -381,3 +382,16 @@ def swap_autosuggestion_down(event: KeyPressEvent):
381382
provider=provider,
382383
direction_method=provider.down,
383384
)
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

IPython/terminal/tests/test_shortcuts.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from IPython.terminal.shortcuts.auto_suggest import (
33
accept,
4-
accept_in_vi_insert_mode,
4+
accept_or_jump_to_end,
55
accept_token,
66
accept_character,
77
accept_word,
@@ -22,6 +22,13 @@
2222
from unittest.mock import patch, Mock
2323

2424

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+
2532
def make_event(text, cursor, suggestion):
2633
event = Mock()
2734
event.current_buffer = Mock()
@@ -80,7 +87,7 @@ def test_autosuggest_at_EOL(text, cursor, suggestion, called):
8087

8188
event = make_event(text, cursor, suggestion)
8289
event.current_buffer.insert_text = Mock()
83-
accept_in_vi_insert_mode(event)
90+
accept_or_jump_to_end(event)
8491
if called:
8592
event.current_buffer.insert_text.assert_called()
8693
else:

0 commit comments

Comments
 (0)