Skip to content

Commit 058a84f

Browse files
committed
Fix the remaining type hint issues.
1 parent 821f62b commit 058a84f

13 files changed

Lines changed: 142 additions & 116 deletions

litecli/clibuffer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
def cli_is_multiline(cli: Any) -> Filter:
1111
@Condition
12-
def cond():
13-
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
12+
def cond() -> bool:
13+
buf = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER)
14+
assert buf is not None
15+
doc = buf.document
1416

1517
if not cli.multi_line:
1618
return False

litecli/clistyle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
PROMPT_STYLE_TO_TOKEN: dict[str, Token] = {v: k for k, v in TOKEN_TO_PROMPT_STYLE.items()}
4747

4848

49-
def parse_pygments_style(token_name: str, style_object, style_dict: dict[str, str]) -> tuple[Token, str]:
49+
def parse_pygments_style(token_name: str, style_object: PygmentsStyle | dict, style_dict: dict[str, str]) -> tuple[Token, str]:
5050
"""Parse token type and style string.
5151
5252
:param token_name: str name of Pygments token. Example: "Token.String"
@@ -55,10 +55,10 @@ def parse_pygments_style(token_name: str, style_object, style_dict: dict[str, st
5555
5656
"""
5757
token_type = string_to_tokentype(token_name)
58-
try:
58+
if isinstance(style_object, PygmentsStyle):
5959
other_token_type = string_to_tokentype(style_dict[token_name])
6060
return token_type, style_object.styles[other_token_type]
61-
except AttributeError:
61+
else:
6262
return token_type, style_dict[token_name]
6363

6464

@@ -90,7 +90,7 @@ def style_factory(name: str, cli_style: dict[str, str]) -> _MergedStyle:
9090
return merge_styles([style_from_pygments_cls(style), override_style, Style(prompt_styles)])
9191

9292

93-
def style_factory_output(name: str, cli_style: dict[str, str]):
93+
def style_factory_output(name: str, cli_style: dict[str, str]) -> PygmentsStyle:
9494
try:
9595
style = pygments.styles.get_style_by_name(name).styles
9696
except ClassNotFound:

litecli/clitoolbar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from __future__ import annotations
22

3-
from typing import Callable
3+
from typing import Callable, Any
44

55
from prompt_toolkit.key_binding.vi_state import InputMode
66
from prompt_toolkit.enums import EditingMode
77
from prompt_toolkit.application import get_app
88

99

10-
def create_toolbar_tokens_func(cli, show_fish_help: Callable[[], bool]) -> Callable[[], list[tuple[str, str]]]:
10+
def create_toolbar_tokens_func(cli: Any, show_fish_help: Callable[[], bool]) -> Callable[[], list[tuple[str, str]]]:
1111
"""Return a function that generates the toolbar tokens."""
1212

1313
def get_toolbar_tokens() -> list[tuple[str, str]]:

litecli/completion_refresher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def refresh(
4545
# if DB is memory, needed to use same connection
4646
# So can't use same connection with different thread
4747
self._bg_refresh(executor, callbacks, completer_options)
48+
return [(None, None, None, "Auto-completion refresh started in the background.")]
4849
else:
4950
self._completer_thread = threading.Thread(
5051
target=self._bg_refresh,
@@ -97,7 +98,7 @@ def _bg_refresh(
9798
callback(completer)
9899

99100

100-
def refresher(name: str, refreshers: dict[str, Callable] = CompletionRefresher.refreshers):
101+
def refresher(name: str, refreshers: dict[str, Callable] = CompletionRefresher.refreshers) -> Callable:
101102
"""Decorator to add the decorated function to the dictionary of
102103
refreshers. Any function decorated with a @refresher will be executed as
103104
part of the completion refresh routine."""

litecli/key_bindings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _(event: KeyPressEvent) -> None:
8585
b.complete_state = None
8686

8787
@kb.add("right", filter=completion_is_selected)
88-
def _(event):
88+
def _(event: KeyPressEvent) -> None:
8989
"""Accept the completion that is selected in the dropdown menu."""
9090
_logger.debug("Detected right-arrow key.")
9191

0 commit comments

Comments
 (0)