Skip to content

Commit 542bc5b

Browse files
krassowskimeeseeksmachine
authored andcommitted
Backport PR ipython#14845: Remove unused variables from auto_suggest and examples, fix typos
1 parent b30c77c commit 542bc5b

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

IPython/terminal/shortcuts/auto_suggest.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from prompt_toolkit.buffer import Buffer
1010
from prompt_toolkit.key_binding import KeyPressEvent
1111
from prompt_toolkit.key_binding.bindings import named_commands as nc
12-
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory, Suggestion, AutoSuggest
12+
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory, Suggestion
1313
from prompt_toolkit.document import Document
1414
from prompt_toolkit.history import History
1515
from prompt_toolkit.shortcuts import PromptSession
@@ -103,9 +103,6 @@ def apply_transformation(self, ti: TransformationInput) -> Transformation:
103103
if len(suggestions) == 0:
104104
return noop("noop: no suggestions")
105105

106-
suggestions_longer_than_buffer: bool = (
107-
len(suggestions) + ti.document.cursor_position_row > ti.document.line_count
108-
)
109106
if prompt_toolkit.VERSION < (3, 0, 49):
110107
if len(suggestions) > 1 and prompt_toolkit.VERSION < (3, 0, 49):
111108
if ti.lineno == ti.document.cursor_position_row:
@@ -132,7 +129,6 @@ def apply_transformation(self, ti: TransformationInput) -> Transformation:
132129
return Transformation(fragments=ti.fragments + [(self.style, suggestion)])
133130
if is_last_line:
134131
if delta < len(suggestions):
135-
extra = f"; {len(suggestions) - delta} line(s) hidden"
136132
suggestion = f"… rest of suggestion ({len(suggestions) - delta} lines) and code hidden"
137133
return Transformation([(self.style, suggestion)])
138134

@@ -171,7 +167,7 @@ class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):
171167
_connected_apps: list[PromptSession]
172168

173169
# handle to the currently running llm task that appends suggestions to the
174-
# current buffer; we keep a handle to it in order to cancell it when there is a cursor movement, or
170+
# current buffer; we keep a handle to it in order to cancel it when there is a cursor movement, or
175171
# another request.
176172
_llm_task: asyncio.Task | None = None
177173

@@ -306,7 +302,7 @@ def down(self, query: str, other_than: str, history: History) -> None:
306302

307303
def _cancel_running_llm_task(self) -> None:
308304
"""
309-
Try to cancell the currently running llm_task if exists, and set it to None.
305+
Try to cancel the currently running llm_task if exists, and set it to None.
310306
"""
311307
if self._llm_task is not None:
312308
if self._llm_task.done():
@@ -353,7 +349,7 @@ async def error_catcher(buffer):
353349
get_ipython().log.error("error")
354350
raise
355351

356-
# here we need a cancellable task so we can't just await the error catched
352+
# here we need a cancellable task so we can't just await the error caught
357353
self._llm_task = asyncio.create_task(error_catcher(buffer))
358354
await self._llm_task
359355

@@ -427,7 +423,7 @@ async def llm_autosuggestion(event: KeyPressEvent):
427423
This will first make sure that the current buffer have _MIN_LINES (7)
428424
available lines to insert the LLM completion
429425
430-
Provisional as of 8.32, may change without warnigns
426+
Provisional as of 8.32, may change without warnings
431427
432428
"""
433429
_MIN_LINES = 5

examples/auto_suggest_llm.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
context.
5454
5555
56-
For more flexibility, subclass the provider, and access the hisotory of IPython
56+
For more flexibility, subclass the provider, and access the history of IPython
5757
via:
5858
5959
```
@@ -66,8 +66,7 @@
6666

6767
import asyncio
6868
import textwrap
69-
from asyncio import FIRST_COMPLETED, Task, create_task, wait
70-
from typing import Any, AsyncIterable, AsyncIterator, Collection, TypeVar
69+
from typing import Any, AsyncIterable, AsyncIterator
7170

7271
from jupyter_ai.completions.models import (
7372
InlineCompletionList,
@@ -79,7 +78,6 @@
7978
from langchain_community.llms import FakeListLLM
8079

8180

82-
from IPython.terminal.shortcuts import Binding
8381
from IPython.terminal.shortcuts.filters import (
8482
navigable_suggestions,
8583
default_buffer_focused,

0 commit comments

Comments
 (0)