fix typechecker errors

This commit is contained in:
2026-01-22 04:48:53 +03:00
parent 838f33db87
commit 088c1720c4
2 changed files with 13 additions and 11 deletions
+11 -9
View File
@@ -1,14 +1,15 @@
__all__ = ["AutoCompleter"] __all__ = ["AutoCompleter"]
import sys import sys
from typing import Callable, Iterable
from prompt_toolkit import PromptSession, HTML from prompt_toolkit import PromptSession, HTML
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.completion import Completer, Completion from prompt_toolkit.completion import Completer, Completion, CompleteEvent
from prompt_toolkit.document import Document from prompt_toolkit.document import Document
from prompt_toolkit.formatted_text import StyleAndTextTuples from prompt_toolkit.formatted_text import StyleAndTextTuples
from prompt_toolkit.history import History, ThreadedHistory, FileHistory, InMemoryHistory from prompt_toolkit.history import History, ThreadedHistory, FileHistory, InMemoryHistory
from prompt_toolkit.key_binding import KeyBindings from prompt_toolkit.key_binding import KeyBindings, KeyPressEvent
from prompt_toolkit.lexers import Lexer from prompt_toolkit.lexers import Lexer
from prompt_toolkit.styles import Style from prompt_toolkit.styles import Style
@@ -17,7 +18,7 @@ class CommandLexer(Lexer):
def __init__(self, valid_commands: set[str]) -> None: def __init__(self, valid_commands: set[str]) -> None:
self.valid_commands: set[str] = valid_commands self.valid_commands: set[str] = valid_commands
def lex_document(self, document): def lex_document(self, document: Document) -> Callable[[int], StyleAndTextTuples]:
def get_line_tokens(lineno: int) -> StyleAndTextTuples: def get_line_tokens(lineno: int) -> StyleAndTextTuples:
if lineno >= len(document.lines): if lineno >= len(document.lines):
return [] return []
@@ -42,7 +43,7 @@ class HistoryCompleter(Completer):
self.history_container: History = history_container self.history_container: History = history_container
self.static_commands: set[str] = static_commands self.static_commands: set[str] = static_commands
def get_completions(self, document: Document, complete_event): def get_completions(self, document: Document, complete_event: CompleteEvent) -> Iterable[Completion]:
text: str = document.text_before_cursor text: str = document.text_before_cursor
history_items: set[str] = set(self.history_container.load_history_strings()) history_items: set[str] = set(self.history_container.load_history_strings())
all_candidates: set[str] = history_items.union(self.static_commands) all_candidates: set[str] = history_items.union(self.static_commands)
@@ -83,7 +84,7 @@ class AutoCompleter:
self.autocomplete_button: str = autocomplete_button self.autocomplete_button: str = autocomplete_button
self.command_highlighting: bool = command_highlighting self.command_highlighting: bool = command_highlighting
self.auto_suggestions: bool = auto_suggestions self.auto_suggestions: bool = auto_suggestions
self._session: PromptSession | None = None self._session: PromptSession[str] | None = None
self._fallback_mode: bool = False self._fallback_mode: bool = False
def initial_setup(self, all_commands: set[str]) -> None: def initial_setup(self, all_commands: set[str]) -> None:
@@ -94,13 +95,13 @@ class AutoCompleter:
kb = KeyBindings() kb = KeyBindings()
def _(event): def _(event: KeyPressEvent) -> None:
buff = event.app.current_buffer buff = event.app.current_buffer
if buff.complete_state: if buff.complete_state:
buff.complete_next() buff.complete_next()
else: else:
completions = list(buff.completer.get_completions(buff.document, None)) completions = list(buff.completer.get_completions(buff.document, CompleteEvent()))
if len(completions) == 1: if len(completions) == 1:
buff.apply_completion(completions[0]) buff.apply_completion(completions[0])
else: else:
@@ -108,9 +109,10 @@ class AutoCompleter:
kb.add(self.autocomplete_button)(_) kb.add(self.autocomplete_button)(_)
history: InMemoryHistory | ThreadedHistory
if self.history_filename: if self.history_filename:
history = FileHistory(self.history_filename) history = ThreadedHistory(FileHistory(self.history_filename))
history = ThreadedHistory(history)
else: else:
history = InMemoryHistory() history = InMemoryHistory()
+2 -2
View File
@@ -38,7 +38,7 @@ class BaseApp:
def __init__( def __init__(
self, self,
*, *,
prompt: str, prompt: str | HTML,
initial_message: str, initial_message: str,
farewell_message: str, farewell_message: str,
exit_command: Command, exit_command: Command,
@@ -49,7 +49,7 @@ class BaseApp:
autocompleter: AutoCompleter, autocompleter: AutoCompleter,
print_func: Printer, print_func: Printer,
) -> None: ) -> None:
self._prompt: str = prompt self._prompt: str | HTML = prompt
self._print_func: Printer = print_func self._print_func: Printer = print_func
self._exit_command: Command = exit_command self._exit_command: Command = exit_command
self._dividing_line: StaticDividingLine | DynamicDividingLine = dividing_line self._dividing_line: StaticDividingLine | DynamicDividingLine = dividing_line