Skip to content

Commit ad1d5bf

Browse files
committed
Type hints for cli_* files.
1 parent 603f92f commit ad1d5bf

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

litecli/clibuffer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# mypy: ignore-errors
22

3-
from __future__ import unicode_literals
3+
from __future__ import annotations
4+
5+
from typing import Any
46

57
from prompt_toolkit.enums import DEFAULT_BUFFER
6-
from prompt_toolkit.filters import Condition
8+
from prompt_toolkit.filters import Condition, Filter
79
from prompt_toolkit.application import get_app
810

911

10-
def cli_is_multiline(cli):
12+
def cli_is_multiline(cli: Any) -> Filter:
1113
@Condition
1214
def cond():
1315
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
@@ -20,7 +22,7 @@ def cond():
2022
return cond
2123

2224

23-
def _multiline_exception(text):
25+
def _multiline_exception(text: str) -> bool:
2426
orig = text
2527
text = text.strip()
2628

litecli/clistyle.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# mypy: ignore-errors
22

3-
from __future__ import unicode_literals
3+
from __future__ import annotations
44

55
import logging
6+
from typing import Dict, List, Tuple
67

78
import pygments.styles
89
from pygments.token import string_to_tokentype, Token
910
from pygments.style import Style as PygmentsStyle
1011
from pygments.util import ClassNotFound
1112
from prompt_toolkit.styles.pygments import style_from_pygments_cls
1213
from prompt_toolkit.styles import merge_styles, Style
14+
from prompt_toolkit.styles.style import _MergedStyle
1315

1416
logger = logging.getLogger(__name__)
1517

1618
# map Pygments tokens (ptk 1.0) to class names (ptk 2.0).
17-
TOKEN_TO_PROMPT_STYLE = {
19+
TOKEN_TO_PROMPT_STYLE: Dict[Token, str] = {
1820
Token.Menu.Completions.Completion.Current: "completion-menu.completion.current",
1921
Token.Menu.Completions.Completion: "completion-menu.completion",
2022
Token.Menu.Completions.Meta.Current: "completion-menu.meta.completion.current",
@@ -43,10 +45,10 @@
4345
}
4446

4547
# reverse dict for cli_helpers, because they still expect Pygments tokens.
46-
PROMPT_STYLE_TO_TOKEN = {v: k for k, v in TOKEN_TO_PROMPT_STYLE.items()}
48+
PROMPT_STYLE_TO_TOKEN: Dict[str, Token] = {v: k for k, v in TOKEN_TO_PROMPT_STYLE.items()}
4749

4850

49-
def parse_pygments_style(token_name, style_object, style_dict):
51+
def parse_pygments_style(token_name: str, style_object, style_dict: Dict[str, str]) -> Tuple[Token, str]:
5052
"""Parse token type and style string.
5153
5254
:param token_name: str name of Pygments token. Example: "Token.String"
@@ -62,13 +64,13 @@ def parse_pygments_style(token_name, style_object, style_dict):
6264
return token_type, style_dict[token_name]
6365

6466

65-
def style_factory(name, cli_style):
67+
def style_factory(name: str, cli_style: Dict[str, str]) -> _MergedStyle:
6668
try:
6769
style = pygments.styles.get_style_by_name(name)
6870
except ClassNotFound:
6971
style = pygments.styles.get_style_by_name("native")
7072

71-
prompt_styles = []
73+
prompt_styles: List[Tuple[str, str]] = []
7274
# prompt-toolkit used pygments tokens for styling before, switched to style
7375
# names in 2.0. Convert old token types to new style names, for backwards compatibility.
7476
for token in cli_style:
@@ -86,11 +88,11 @@ def style_factory(name, cli_style):
8688
# https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py
8789
prompt_styles.append((token, cli_style[token]))
8890

89-
override_style = Style([("bottom-toolbar", "noreverse")])
91+
override_style: Style = Style([("bottom-toolbar", "noreverse")])
9092
return merge_styles([style_from_pygments_cls(style), override_style, Style(prompt_styles)])
9193

9294

93-
def style_factory_output(name, cli_style):
95+
def style_factory_output(name: str, cli_style: Dict[str, str]):
9496
try:
9597
style = pygments.styles.get_style_by_name(name).styles
9698
except ClassNotFound:

litecli/clitoolbar.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# mypy: ignore-errors
22

3-
from __future__ import unicode_literals
3+
from __future__ import annotations
4+
5+
from typing import Callable, List, Tuple
46

57
from prompt_toolkit.key_binding.vi_state import InputMode
68
from prompt_toolkit.enums import EditingMode
79
from prompt_toolkit.application import get_app
810

911

10-
def create_toolbar_tokens_func(cli, show_fish_help):
11-
"""
12-
Return a function that generates the toolbar tokens.
13-
"""
12+
def create_toolbar_tokens_func(cli, show_fish_help: Callable[[], bool]) -> Callable[[], List[Tuple[str, str]]]:
13+
"""Return a function that generates the toolbar tokens."""
1414

15-
def get_toolbar_tokens():
16-
result = []
15+
def get_toolbar_tokens() -> List[Tuple[str, str]]:
16+
result: List[Tuple[str, str]] = []
1717
result.append(("class:bottom-toolbar", " "))
1818

1919
if cli.multi_line:
@@ -37,7 +37,7 @@ def get_toolbar_tokens():
3737
return get_toolbar_tokens
3838

3939

40-
def _get_vi_mode():
40+
def _get_vi_mode() -> str:
4141
"""Get the current vi mode for display."""
4242
return {
4343
InputMode.INSERT: "I",

litecli/packages/special/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def run_external_cmd(
8888
sys.argv = original_args
8989

9090

91-
def build_command_tree(cmd: click.BaseCommand) -> Optional[Dict[str, Any]]:
91+
def build_command_tree(cmd: click.Command) -> Optional[Dict[str, Any]]:
9292
"""Recursively build a command tree for a Click app.
9393
9494
Args:

0 commit comments

Comments
 (0)