Migrate type checker to ty

Much faster than mypy. Matches usage of ruff from same developer.
This commit is contained in:
Kovid Goyal
2026-07-04 09:16:05 +05:30
parent bb452f2066
commit a65b4c70a7
45 changed files with 218 additions and 238 deletions

View File

@@ -51,8 +51,8 @@ class Broadcast(Handler):
self.cmd.clear_to_end_of_screen()
self.line_edit.write(self.write, screen_cols=self.screen_size.cols)
def on_resize(self, screen_size: ScreenSize) -> None:
super().on_resize(screen_size)
def on_resize(self, new_size: ScreenSize) -> None:
super().on_resize(new_size)
self.commit_line()
def on_text(self, text: str, in_bracketed_paste: bool = False) -> None:

View File

@@ -297,7 +297,7 @@ def linenum_handle_result(args: list[str], data: dict[str, Any], target_window_i
def is_copy_action(s: str) -> bool:
return s in ('-', '@', '*') or s.startswith('@')
programs = list(filter(is_copy_action, data['programs'] or ()))
programs = list(filter(is_copy_action, data['programs'] or []))
# keep for backward compatibility, previously option `--program` does not need to be specified to perform copy actions
if is_copy_action(cmd[0]):
programs.append(cmd.pop(0))
@@ -412,7 +412,8 @@ def handle_result(args: list[str], data: dict[str, Any], target_window_id: int,
w = boss.window_id_map.get(target_window_id)
boss.call_remote_control(self_window=w, args=tuple(launch_args + ([m] if isinstance(m, str) else m)))
else:
boss.open_url(m, program, cwd=cwd)
if isinstance(m, str):
boss.open_url(m, program, cwd=cwd)
if __name__ == '__main__':

View File

@@ -102,7 +102,7 @@ class KittenUI:
raise ValueError('Remote control is not enabled, remember to use allow_remote_control=True')
prefix = [kitten_exe(), '@']
r = -1
pass_fds = list(kw.get('pass_fds') or ())
pass_fds = list(kw.get('pass_fds') or [])
try:
if self.rc_fd > -1:
pass_fds.append(self.rc_fd)
@@ -200,12 +200,13 @@ class Handler:
self.debug.fobj = self
self.initialize()
def __exit__(self, etype: type, value: Exception, tb: TracebackType) -> None:
def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, tb: TracebackType | None) -> bool | None:
del self.debug.fobj
with suppress(Exception):
self.finalize()
if self._image_manager is not None:
self._image_manager.__exit__(etype, value, tb)
self._image_manager.__exit__(exc_type, exc_val, tb)
return None
def initialize(self) -> None:
pass
@@ -213,8 +214,8 @@ class Handler:
def finalize(self) -> None:
pass
def on_resize(self, screen_size: ScreenSize) -> None:
self.screen_size = screen_size
def on_resize(self, new_size: ScreenSize) -> None:
self.screen_size = new_size
def quit_loop(self, return_code: int | None = None) -> None:
self._tui_loop.quit(return_code)

View File

@@ -10,7 +10,7 @@ from collections.abc import Callable, Iterator, Sequence
from contextlib import suppress
from enum import IntEnum
from itertools import count
from typing import Any, ClassVar, DefaultDict, Deque, Generic, Optional, TypeVar, Union, cast
from typing import Any, ClassVar, DefaultDict, Deque, Generic, Optional, TypeVar, Union, cast, final
from kitty.conf.utils import positive_float, positive_int
from kitty.fast_data_types import create_canvas
@@ -343,6 +343,7 @@ class Alias(Generic[T]):
self.name = Alias.currently_processing
@final
class GraphicsCommand:
a = action = Alias('t')
q = quiet = Alias(0)
@@ -467,12 +468,13 @@ class ImageManager:
gc.t = 'f'
self.handler.cmd.gr_command(gc, standard_b64encode(f.name.encode(fsenc)))
def __exit__(self, *a: Any) -> None:
def __exit__(self, *a: Any) -> bool | None:
import shutil
shutil.rmtree(self.tdir, ignore_errors=True)
self.handler.cmd.clear_images_on_screen(delete_data=True)
self.delete_all_sent_images()
del self.handler
return None
def delete_all_sent_images(self) -> None:
gc = GraphicsCommand()

View File

@@ -84,7 +84,7 @@ class PathCompleter:
import readline
from .dircolors import Dircolors
if 'libedit' in readline.__doc__:
if 'libedit' in getattr(readline, '__doc__', '') or '':
readline.parse_and_bind("bind -e")
readline.parse_and_bind("bind '\t' rl_complete")
else: