Add more type annotations
This commit is contained in:
parent
c899eb4ee3
commit
60472fcee3
@ -156,7 +156,7 @@ class Handler:
|
|||||||
def on_writing_finished(self) -> None:
|
def on_writing_finished(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_kitty_cmd_response(self, response: Dict) -> None:
|
def on_kitty_cmd_response(self, response: Dict[str, Any]) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_clipboard_response(self, text: str, from_primary: bool = False) -> None:
|
def on_clipboard_response(self, text: str, from_primary: bool = False) -> None:
|
||||||
@ -199,7 +199,7 @@ class HandleResult:
|
|||||||
type_of_input: Optional[str] = None
|
type_of_input: Optional[str] = None
|
||||||
no_ui: bool = False
|
no_ui: bool = False
|
||||||
|
|
||||||
def __init__(self, impl: Callable, type_of_input: Optional[str], no_ui: bool):
|
def __init__(self, impl: Callable[..., Any], type_of_input: Optional[str], no_ui: bool):
|
||||||
self.impl = impl
|
self.impl = impl
|
||||||
self.no_ui = no_ui
|
self.no_ui = no_ui
|
||||||
self.type_of_input = type_of_input
|
self.type_of_input = type_of_input
|
||||||
@ -208,9 +208,9 @@ class HandleResult:
|
|||||||
return self.impl(args, data, target_window_id, boss)
|
return self.impl(args, data, target_window_id, boss)
|
||||||
|
|
||||||
|
|
||||||
def result_handler(type_of_input: Optional[str] = None, no_ui: bool = False) -> Callable[[Callable], HandleResult]:
|
def result_handler(type_of_input: Optional[str] = None, no_ui: bool = False) -> Callable[[Callable[..., Any]], HandleResult]:
|
||||||
|
|
||||||
def wrapper(impl: Callable) -> HandleResult:
|
def wrapper(impl: Callable[..., Any]) -> HandleResult:
|
||||||
return HandleResult(impl, type_of_input, no_ui)
|
return HandleResult(impl, type_of_input, no_ui)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|||||||
@ -132,7 +132,7 @@ class OutdatedImageMagick(ValueError):
|
|||||||
last_imagemagick_cmd: Sequence[str] = ()
|
last_imagemagick_cmd: Sequence[str] = ()
|
||||||
|
|
||||||
|
|
||||||
def run_imagemagick(path: str, cmd: Sequence[str], keep_stdout: bool = True) -> CompletedProcess:
|
def run_imagemagick(path: str, cmd: Sequence[str], keep_stdout: bool = True) -> 'CompletedProcess[bytes]':
|
||||||
global last_imagemagick_cmd
|
global last_imagemagick_cmd
|
||||||
import subprocess
|
import subprocess
|
||||||
last_imagemagick_cmd = cmd
|
last_imagemagick_cmd = cmd
|
||||||
|
|||||||
@ -193,19 +193,17 @@ class SignalManager:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
loop: asyncio.AbstractEventLoop,
|
loop: asyncio.AbstractEventLoop,
|
||||||
on_winch: Callable,
|
on_winch: Callable[[], None],
|
||||||
on_interrupt: Callable,
|
on_interrupt: Callable[[], None],
|
||||||
on_term: Callable
|
on_term: Callable[[], None],
|
||||||
) -> None:
|
) -> None:
|
||||||
self.asycio_loop = loop
|
self.asycio_loop = loop
|
||||||
self.on_winch, self.on_interrupt, self.on_term = on_winch, on_interrupt, on_term
|
self.on_winch, self.on_interrupt, self.on_term = on_winch, on_interrupt, on_term
|
||||||
|
|
||||||
def __enter__(self) -> None:
|
def __enter__(self) -> None:
|
||||||
tuple(map(lambda x: self.asycio_loop.add_signal_handler(*x), (
|
self.asycio_loop.add_signal_handler(signal.SIGWINCH, self.on_winch)
|
||||||
(signal.SIGWINCH, self.on_winch),
|
self.asycio_loop.add_signal_handler(signal.SIGINT, self.on_interrupt)
|
||||||
(signal.SIGINT, self.on_interrupt),
|
self.asycio_loop.add_signal_handler(signal.SIGTERM, self.on_term)
|
||||||
(signal.SIGTERM, self.on_term)
|
|
||||||
)))
|
|
||||||
|
|
||||||
def __exit__(self, *a: Any) -> None:
|
def __exit__(self, *a: Any) -> None:
|
||||||
tuple(map(self.asycio_loop.remove_signal_handler, (
|
tuple(map(self.asycio_loop.remove_signal_handler, (
|
||||||
|
|||||||
@ -23,7 +23,7 @@ RESTORE_PRIVATE_MODE_VALUES = '\033[?r'
|
|||||||
SAVE_COLORS = '\033[#P'
|
SAVE_COLORS = '\033[#P'
|
||||||
RESTORE_COLORS = '\033[#Q'
|
RESTORE_COLORS = '\033[#Q'
|
||||||
F = TypeVar('F')
|
F = TypeVar('F')
|
||||||
all_cmds: Dict[str, Callable] = {}
|
all_cmds: Dict[str, Callable[..., Any]] = {}
|
||||||
|
|
||||||
|
|
||||||
class Mode(Enum):
|
class Mode(Enum):
|
||||||
@ -264,7 +264,7 @@ def serialize_gr_command(cmd: Dict[str, Union[int, str]], payload: Optional[byte
|
|||||||
|
|
||||||
|
|
||||||
@cmd
|
@cmd
|
||||||
def gr_command(cmd: Union[Dict, 'GraphicsCommandType'], payload: Optional[bytes] = None) -> str:
|
def gr_command(cmd: Union[Dict[str, Union[int, str]], 'GraphicsCommandType'], payload: Optional[bytes] = None) -> str:
|
||||||
if isinstance(cmd, dict):
|
if isinstance(cmd, dict):
|
||||||
raw = serialize_gr_command(cmd, payload)
|
raw = serialize_gr_command(cmd, payload)
|
||||||
else:
|
else:
|
||||||
@ -428,7 +428,7 @@ def request_from_clipboard(use_primary: bool = False) -> str:
|
|||||||
# Boilerplate to make operations available via Handler.cmd {{{
|
# Boilerplate to make operations available via Handler.cmd {{{
|
||||||
|
|
||||||
|
|
||||||
def writer(handler: HandlerType, func: Callable) -> Callable:
|
def writer(handler: HandlerType, func: Callable[..., Union[bytes, str]]) -> Callable[..., None]:
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def f(*a: Any, **kw: Any) -> None:
|
def f(*a: Any, **kw: Any) -> None:
|
||||||
handler.write(func(*a, **kw))
|
handler.write(func(*a, **kw))
|
||||||
@ -442,7 +442,7 @@ def commander(handler: HandlerType) -> CMD:
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def func_sig(func: Callable) -> Generator[str, None, None]:
|
def func_sig(func: Callable[..., Any]) -> Generator[str, None, None]:
|
||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
s = inspect.signature(func)
|
s = inspect.signature(func)
|
||||||
|
|||||||
@ -11,7 +11,7 @@ from functools import partial as p, wraps
|
|||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, Callable, Dict, Iterable, Iterator, List, MutableSequence, Optional,
|
Any, Callable, Dict, Iterable, Iterator, List, MutableSequence, Optional,
|
||||||
Sequence, Tuple, cast
|
Sequence, Tuple
|
||||||
)
|
)
|
||||||
|
|
||||||
scale = (0.001, 1., 1.5, 2.)
|
scale = (0.001, 1., 1.5, 2.)
|
||||||
@ -168,11 +168,11 @@ class SSByteArray(bytearray):
|
|||||||
supersample_factor = 1
|
supersample_factor = 1
|
||||||
|
|
||||||
|
|
||||||
def supersampled(supersample_factor: int = 4) -> Callable:
|
def supersampled(supersample_factor: int = 4) -> Callable[[Callable[..., None]], Callable[..., None]]:
|
||||||
# Anti-alias the drawing performed by the wrapped function by
|
# Anti-alias the drawing performed by the wrapped function by
|
||||||
# using supersampling
|
# using supersampling
|
||||||
|
|
||||||
def create_wrapper(f: Callable) -> Callable:
|
def create_wrapper(f: Callable[..., None]) -> Callable[..., None]:
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def supersampled_wrapper(buf: BufType, width: int, height: int, *args: Any, **kw: Any) -> None:
|
def supersampled_wrapper(buf: BufType, width: int, height: int, *args: Any, **kw: Any) -> None:
|
||||||
w, h = supersample_factor * width, supersample_factor * height
|
w, h = supersample_factor * width, supersample_factor * height
|
||||||
@ -781,7 +781,7 @@ def braille(buf: BufType, width: int, height: int, which: int = 0) -> None:
|
|||||||
braille_dot(buf, width, height, col, row)
|
braille_dot(buf, width, height, col, row)
|
||||||
|
|
||||||
|
|
||||||
box_chars: Dict[str, List[Callable]] = {
|
box_chars: Dict[str, List[Callable[[BufType, int, int], Any]]] = {
|
||||||
'─': [hline],
|
'─': [hline],
|
||||||
'━': [p(hline, level=3)],
|
'━': [p(hline, level=3)],
|
||||||
'│': [vline],
|
'│': [vline],
|
||||||
@ -1008,7 +1008,7 @@ for starts, func, pattern in (
|
|||||||
|
|
||||||
for chars, func_ in (('╒╕╘╛', dvcorner), ('╓╖╙╜', dhcorner), ('╔╗╚╝', dcorner), ('╟╢╤╧', dpip)):
|
for chars, func_ in (('╒╕╘╛', dvcorner), ('╓╖╙╜', dhcorner), ('╔╗╚╝', dcorner), ('╟╢╤╧', dpip)):
|
||||||
for ch in chars:
|
for ch in chars:
|
||||||
box_chars[ch] = [p(cast(Callable, func_), which=ch)]
|
box_chars[ch] = [p(func_, which=ch)]
|
||||||
|
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
box_chars[chr(0x2800 + i)] = [p(braille, which=i)]
|
box_chars[chr(0x2800 + i)] = [p(braille, which=i)]
|
||||||
|
|||||||
@ -22,7 +22,7 @@ def get_output_variables(left_address: int, right_address: int, color_address: i
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def marker_from_regex(expression: Union[str, Pattern], color: int, flags: int = re.UNICODE) -> MarkerFunc:
|
def marker_from_regex(expression: Union[str, 'Pattern[str]'], color: int, flags: int = re.UNICODE) -> MarkerFunc:
|
||||||
color = max(1, min(color, 3))
|
color = max(1, min(color, 3))
|
||||||
if isinstance(expression, str):
|
if isinstance(expression, str):
|
||||||
pat = re.compile(expression, flags=flags)
|
pat = re.compile(expression, flags=flags)
|
||||||
|
|||||||
@ -194,12 +194,12 @@ def reset_registry() -> None:
|
|||||||
id_counter = count()
|
id_counter = count()
|
||||||
|
|
||||||
|
|
||||||
def notify_with_command(cmd: NotificationCommand, window_id: int, notify: NotifyImplementation = notify_implementation) -> None:
|
def notify_with_command(cmd: NotificationCommand, window_id: int, notify_implementation: NotifyImplementation = notify_implementation) -> None:
|
||||||
title = cmd.title or cmd.body
|
title = cmd.title or cmd.body
|
||||||
body = cmd.body if cmd.title else ''
|
body = cmd.body if cmd.title else ''
|
||||||
if title:
|
if title:
|
||||||
identifier = 'i' + str(next(id_counter))
|
identifier = 'i' + str(next(id_counter))
|
||||||
notify_implementation(title, body, identifier=identifier)
|
notify_implementation(title, body, identifier)
|
||||||
register_identifier(identifier, cmd, window_id)
|
register_identifier(identifier, cmd, window_id)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user