mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-19 15:04:50 +02:00
Add more type annotations
This commit is contained in:
@@ -156,7 +156,7 @@ class Handler:
|
||||
def on_writing_finished(self) -> None:
|
||||
pass
|
||||
|
||||
def on_kitty_cmd_response(self, response: Dict) -> None:
|
||||
def on_kitty_cmd_response(self, response: Dict[str, Any]) -> None:
|
||||
pass
|
||||
|
||||
def on_clipboard_response(self, text: str, from_primary: bool = False) -> None:
|
||||
@@ -199,7 +199,7 @@ class HandleResult:
|
||||
type_of_input: Optional[str] = None
|
||||
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.no_ui = no_ui
|
||||
self.type_of_input = type_of_input
|
||||
@@ -208,9 +208,9 @@ class HandleResult:
|
||||
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 wrapper
|
||||
|
||||
@@ -132,7 +132,7 @@ class OutdatedImageMagick(ValueError):
|
||||
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
|
||||
import subprocess
|
||||
last_imagemagick_cmd = cmd
|
||||
|
||||
@@ -193,19 +193,17 @@ class SignalManager:
|
||||
def __init__(
|
||||
self,
|
||||
loop: asyncio.AbstractEventLoop,
|
||||
on_winch: Callable,
|
||||
on_interrupt: Callable,
|
||||
on_term: Callable
|
||||
on_winch: Callable[[], None],
|
||||
on_interrupt: Callable[[], None],
|
||||
on_term: Callable[[], None],
|
||||
) -> None:
|
||||
self.asycio_loop = loop
|
||||
self.on_winch, self.on_interrupt, self.on_term = on_winch, on_interrupt, on_term
|
||||
|
||||
def __enter__(self) -> None:
|
||||
tuple(map(lambda x: self.asycio_loop.add_signal_handler(*x), (
|
||||
(signal.SIGWINCH, self.on_winch),
|
||||
(signal.SIGINT, self.on_interrupt),
|
||||
(signal.SIGTERM, self.on_term)
|
||||
)))
|
||||
self.asycio_loop.add_signal_handler(signal.SIGWINCH, self.on_winch)
|
||||
self.asycio_loop.add_signal_handler(signal.SIGINT, self.on_interrupt)
|
||||
self.asycio_loop.add_signal_handler(signal.SIGTERM, self.on_term)
|
||||
|
||||
def __exit__(self, *a: Any) -> None:
|
||||
tuple(map(self.asycio_loop.remove_signal_handler, (
|
||||
|
||||
@@ -23,7 +23,7 @@ RESTORE_PRIVATE_MODE_VALUES = '\033[?r'
|
||||
SAVE_COLORS = '\033[#P'
|
||||
RESTORE_COLORS = '\033[#Q'
|
||||
F = TypeVar('F')
|
||||
all_cmds: Dict[str, Callable] = {}
|
||||
all_cmds: Dict[str, Callable[..., Any]] = {}
|
||||
|
||||
|
||||
class Mode(Enum):
|
||||
@@ -264,7 +264,7 @@ def serialize_gr_command(cmd: Dict[str, Union[int, str]], payload: Optional[byte
|
||||
|
||||
|
||||
@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):
|
||||
raw = serialize_gr_command(cmd, payload)
|
||||
else:
|
||||
@@ -428,7 +428,7 @@ def request_from_clipboard(use_primary: bool = False) -> str:
|
||||
# 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)
|
||||
def f(*a: Any, **kw: Any) -> None:
|
||||
handler.write(func(*a, **kw))
|
||||
@@ -442,7 +442,7 @@ def commander(handler: HandlerType) -> CMD:
|
||||
return ans
|
||||
|
||||
|
||||
def func_sig(func: Callable) -> Generator[str, None, None]:
|
||||
def func_sig(func: Callable[..., Any]) -> Generator[str, None, None]:
|
||||
import inspect
|
||||
import re
|
||||
s = inspect.signature(func)
|
||||
|
||||
Reference in New Issue
Block a user