From 4494ddd8ff67c48ae612920a595eb39ae79d91cb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 26 Oct 2021 22:39:14 +0530 Subject: [PATCH] mypy: Turn on return value checks Its a shame GvR is married to "return None" https://github.com/python/mypy/issues/7511 --- kittens/broadcast/main.py | 1 + kittens/diff/patch.py | 1 + kittens/hints/main.py | 1 + kittens/remote_file/main.py | 4 +- kittens/themes/main.py | 1 + kittens/transfer/send.py | 2 + kittens/tui/handler.py | 1 + kittens/tui/path_completer.py | 2 + kittens/unicode_input/main.py | 1 + kitty/boss.py | 86 ++++++++++++++++-------------- kitty/child.py | 2 + kitty/file_transmission.py | 1 + kitty/fonts/box_drawing.py | 11 ++-- kitty/layout/base.py | 1 + kitty/layout/grid.py | 1 + kitty/layout/splits.py | 2 + kitty/layout/tall.py | 1 + kitty/notify.py | 1 + kitty/options/utils.py | 2 +- kitty/rc/close_tab.py | 1 + kitty/rc/close_window.py | 1 + kitty/rc/create_marker.py | 1 + kitty/rc/detach_tab.py | 1 + kitty/rc/detach_window.py | 1 + kitty/rc/disable_ligatures.py | 1 + kitty/rc/env.py | 1 + kitty/rc/focus_tab.py | 1 + kitty/rc/focus_window.py | 1 + kitty/rc/goto_layout.py | 1 + kitty/rc/kitten.py | 1 + kitty/rc/last_used_layout.py | 1 + kitty/rc/remove_marker.py | 1 + kitty/rc/resize_os_window.py | 1 + kitty/rc/scroll_window.py | 1 + kitty/rc/send_text.py | 1 + kitty/rc/set_background_image.py | 1 + kitty/rc/set_background_opacity.py | 1 + kitty/rc/set_colors.py | 1 + kitty/rc/set_enabled_layouts.py | 1 + kitty/rc/set_font_size.py | 1 + kitty/rc/set_spacing.py | 1 + kitty/rc/set_tab_color.py | 1 + kitty/rc/set_tab_title.py | 1 + kitty/rc/set_window_title.py | 1 + kitty/rc/signal_child.py | 1 + kitty/shell_integration.py | 3 +- kitty/tab_bar.py | 1 + kitty/tabs.py | 6 +++ kitty/utils.py | 4 ++ kitty/window.py | 1 + kitty/window_list.py | 9 ++++ setup.cfg | 1 - 52 files changed, 124 insertions(+), 49 deletions(-) diff --git a/kittens/broadcast/main.py b/kittens/broadcast/main.py index 06cd555c9..ed518dd9d 100644 --- a/kittens/broadcast/main.py +++ b/kittens/broadcast/main.py @@ -106,6 +106,7 @@ def main(args: List[str]) -> Optional[Dict[str, Any]]: loop = Loop() handler = Broadcast(opts, items) loop.loop(handler) + return None if __name__ == '__main__': diff --git a/kittens/diff/patch.py b/kittens/diff/patch.py index 2e791d47a..0042af76e 100644 --- a/kittens/diff/patch.py +++ b/kittens/diff/patch.py @@ -24,6 +24,7 @@ def find_differ() -> Optional[str]: return GIT_DIFF if shutil.which('diff'): return DIFF_DIFF + return None def set_diff_command(opt: str) -> None: diff --git a/kittens/hints/main.py b/kittens/hints/main.py index cda7d8d35..c6b34cbd2 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -688,6 +688,7 @@ def main(args: List[str]) -> Optional[Dict[str, Any]]: import traceback traceback.print_exc() input(_('Press Enter to quit')) + return None def linenum_handle_result(args: List[str], data: Dict[str, Any], target_window_id: int, boss: BossType, extra_cli_args: Sequence[str], *a: Any) -> None: diff --git a/kittens/remote_file/main.py b/kittens/remote_file/main.py index 4ba8f07e9..024f5a3a4 100644 --- a/kittens/remote_file/main.py +++ b/kittens/remote_file/main.py @@ -132,7 +132,7 @@ class ControlMaster: self.dest = os.path.join(self.tdir, os.path.basename(self.remote_path)) return self - def __exit__(self, *a: Any) -> bool: + def __exit__(self, *a: Any) -> None: subprocess.Popen( self.batch_cmd_prefix + ['-O', 'exit', self.conn_data.hostname], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL @@ -215,6 +215,7 @@ def main(args: List[str]) -> Result: import traceback traceback.print_exc() show_error('Failed with unhandled exception') + return None def save_as(conn_data: SSHConnectionData, remote_path: str, cli_opts: RemoteFileCLIOptions) -> None: @@ -312,6 +313,7 @@ def handle_action(action: str, cli_opts: RemoteFileCLIOptions) -> Result: elif action == 'save': print('Saving', cli_opts.path, 'from', cli_opts.hostname) save_as(conn_data, remote_path, cli_opts) + return None @result_handler() diff --git a/kittens/themes/main.py b/kittens/themes/main.py index 2c3f59a47..c2b6e08a2 100644 --- a/kittens/themes/main.py +++ b/kittens/themes/main.py @@ -203,6 +203,7 @@ class ThemesHandler(Handler): col = color_as_sharp(color_from_int(o.color_table[i])) cmds.append(f'{i};{col}') self.print(end='\033]4;' + ';'.join(cmds) + '\033\\') + return True def redraw_after_category_change(self) -> None: self.themes_list.update_themes(self.all_themes.filtered(self.filter_map[self.current_category])) diff --git a/kittens/transfer/send.py b/kittens/transfer/send.py index 5ed7244b2..f20bd8659 100644 --- a/kittens/transfer/send.py +++ b/kittens/transfer/send.py @@ -312,6 +312,7 @@ class SendManager: ans = self.files[self.active_idx] if ans.state is FileState.transmitting: return ans + return None def activate_next_ready_file(self) -> Optional[File]: if self.active_idx is not None: @@ -325,6 +326,7 @@ class SendManager: return f self.active_idx = None self.update_collective_statuses() + return None def update_collective_statuses(self) -> None: found_not_started = found_not_done = False diff --git a/kittens/tui/handler.py b/kittens/tui/handler.py index 766d88096..0c2b7aad7 100644 --- a/kittens/tui/handler.py +++ b/kittens/tui/handler.py @@ -83,6 +83,7 @@ class Handler: for sc, action in self._key_shortcuts.items(): if key_event.matches(sc): return action + return None def __enter__(self) -> None: if self._image_manager is not None: diff --git a/kittens/tui/path_completer.py b/kittens/tui/path_completer.py index 3291fbc57..970cb025f 100644 --- a/kittens/tui/path_completer.py +++ b/kittens/tui/path_completer.py @@ -132,6 +132,7 @@ class PathCompleter: options = self.cache[text] = tuple(find_completions(text)) if options and state < len(options): return options[state] + return None def __exit__(self, *a: Any) -> bool: import readline @@ -143,6 +144,7 @@ class PathCompleter: def input(self) -> str: with self: return input(self.prompt) + return '' def develop() -> None: diff --git a/kittens/unicode_input/main.py b/kittens/unicode_input/main.py index 2167c05f6..f7132858a 100644 --- a/kittens/unicode_input/main.py +++ b/kittens/unicode_input/main.py @@ -157,6 +157,7 @@ class Table: def current_codepoint(self) -> Optional[int]: if self.codepoints: return self.codepoints[self.current_idx] + return None def set_codepoints(self, codepoints: List[int], mode: str = HEX, current_idx: int = 0) -> None: self.codepoints = codepoints diff --git a/kitty/boss.py b/kitty/boss.py index ade063589..6e2d45a6a 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -9,8 +9,8 @@ from contextlib import suppress from functools import partial from gettext import gettext as _ from typing import ( - Any, Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union, - cast + Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, + Union, cast ) from weakref import WeakValueDictionary @@ -27,16 +27,16 @@ from .constants import ( ) from .fast_data_types import ( CLOSE_BEING_CONFIRMED, GLFW_MOD_ALT, GLFW_MOD_CONTROL, GLFW_MOD_SHIFT, - GLFW_MOD_SUPER, IMPERATIVE_CLOSE_REQUESTED, NO_CLOSE_REQUESTED, - ChildMonitor, KeyEvent, add_timer, apply_options_update, - background_opacity_of, change_background_opacity, change_os_window_state, - cocoa_set_menubar_title, create_os_window, GLFW_PRESS, GLFW_MOUSE_BUTTON_LEFT, - current_application_quit_request, current_os_window, destroy_global_data, - focus_os_window, get_clipboard_string, get_options, get_os_window_size, - global_font_size, mark_os_window_for_close, os_window_font_size, - patch_global_colors, redirect_mouse_handling, ring_bell, safe_pipe, - set_application_quit_request, set_background_image, set_boss, - set_clipboard_string, set_in_sequence_mode, set_options, + GLFW_MOD_SUPER, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, + IMPERATIVE_CLOSE_REQUESTED, NO_CLOSE_REQUESTED, ChildMonitor, KeyEvent, + add_timer, apply_options_update, background_opacity_of, + change_background_opacity, change_os_window_state, cocoa_set_menubar_title, + create_os_window, current_application_quit_request, current_os_window, + destroy_global_data, focus_os_window, get_clipboard_string, get_options, + get_os_window_size, global_font_size, mark_os_window_for_close, + os_window_font_size, patch_global_colors, redirect_mouse_handling, + ring_bell, safe_pipe, set_application_quit_request, set_background_image, + set_boss, set_clipboard_string, set_in_sequence_mode, set_options, set_os_window_size, thread_write, toggle_fullscreen, toggle_maximized ) from .key_encoding import get_name_to_functional_number_map @@ -234,7 +234,7 @@ class Boss: self.os_window_map[os_window_id] = tm return os_window_id - def list_os_windows(self, self_window: Optional[Window] = None) -> Generator[OSWindowDict, None, None]: + def list_os_windows(self, self_window: Optional[Window] = None) -> Iterator[OSWindowDict]: with cached_process_data(): active_tab, active_window = self.active_tab, self.active_window active_tab_manager = self.active_tab_manager @@ -249,20 +249,20 @@ class Boss: } @property - def all_tab_managers(self) -> Generator[TabManager, None, None]: + def all_tab_managers(self) -> Iterator[TabManager]: yield from self.os_window_map.values() @property - def all_tabs(self) -> Generator[Tab, None, None]: + def all_tabs(self) -> Iterator[Tab]: for tm in self.all_tab_managers: yield from tm @property - def all_windows(self) -> Generator[Window, None, None]: + def all_windows(self) -> Iterator[Window]: for tab in self.all_tabs: yield from tab - def match_windows(self, match: str) -> Generator[Window, None, None]: + def match_windows(self, match: str) -> Iterator[Window]: try: field, exp = match.split(':', 1) except ValueError: @@ -305,8 +305,9 @@ class Boss: for w in tab: if w.id == window.id: return tab + return None - def match_tabs(self, match: str) -> Generator[Tab, None, None]: + def match_tabs(self, match: str) -> Iterator[Tab]: try: field, exp = match.split(':', 1) except ValueError: @@ -359,6 +360,7 @@ class Boss: if switch_os_window_if_needed and current_os_window() != os_window_id: focus_os_window(os_window_id, True) return os_window_id + return None def _new_os_window(self, args: Union[SpecialWindowInstance, Iterable[str]], cwd_from: Optional[int] = None) -> int: if isinstance(args, SpecialWindowInstance): @@ -377,6 +379,7 @@ class Boss: t = self.active_tab if t is not None: return t.active_window_for_cwd + return None @ac('win', 'New OS Window with the same working directory as the currently active window') def new_os_window_with_cwd(self, *args: str) -> None: @@ -595,7 +598,7 @@ class Boss: run_update_check(get_options().update_check_interval * 60 * 60) self.update_check_started = True - def handle_click_on_tab(self, os_window_id: int, x: int, button: int, modifiers: int, action: int) -> int: + def handle_click_on_tab(self, os_window_id: int, x: int, button: int, modifiers: int, action: int) -> None: tm = self.os_window_map.get(os_window_id) if tm is not None: tm.handle_click_on_tab(x, button, modifiers, action) @@ -751,20 +754,17 @@ class Boss: @property def active_tab_manager(self) -> Optional[TabManager]: os_window_id = current_os_window() - if os_window_id is not None: - return self.os_window_map.get(os_window_id) + return None if os_window_id is None else self.os_window_map.get(os_window_id) @property def active_tab(self) -> Optional[Tab]: tm = self.active_tab_manager - if tm is not None: - return tm.active_tab + return None if tm is None else tm.active_tab @property def active_window(self) -> Optional[Window]: t = self.active_tab - if t is not None: - return t.active_window + return None if t is None else t.active_window def set_pending_sequences(self, sequences: SubSequenceMap, default_pending_action: Optional[KeyAction] = None) -> None: self.pending_sequences = sequences @@ -783,6 +783,7 @@ class Boss: return True elif isinstance(key_action, KeyAction): return self.dispatch_action(key_action) + return False def clear_pending_sequences(self) -> None: self.pending_sequences = self.default_pending_action = None @@ -1530,7 +1531,7 @@ class Boss: else: subprocess.Popen(cmd, env=env, cwd=cwd) - def pipe(self, source: str, dest: str, exe: str, *args: str) -> Window: + def pipe(self, source: str, dest: str, exe: str, *args: str) -> Optional[Window]: cmd = [exe] + list(args) window = self.active_window cwd_from = window.child.pid_for_cwd if window else None @@ -1559,6 +1560,7 @@ class Boss: else: env, stdin = self.process_stdin_source(stdin=source, window=window) self.run_background_process(cmd, cwd_from=cwd_from, stdin=stdin, env=env) + return None def args_to_special_window(self, args: Iterable[str], cwd_from: Optional[int] = None) -> SpecialWindowInstance: args = list(args) @@ -1591,6 +1593,7 @@ class Boss: tm = self.active_tab_manager if tm is not None: return tm.new_tab(special_window=special_window, cwd_from=cwd_from, as_neighbor=as_neighbor) + return None def _create_tab(self, args: List[str], cwd_from: Optional[int] = None) -> None: as_neighbor = False @@ -1615,21 +1618,22 @@ class Boss: def _new_window(self, args: List[str], cwd_from: Optional[int] = None) -> Optional[Window]: tab = self.active_tab - if tab is not None: - allow_remote_control = False - location = None - if args and args[0].startswith('!'): - location = args[0][1:].lower() - args = args[1:] - if args and args[0] == '@': - args = args[1:] - allow_remote_control = True - if args: - return tab.new_special_window( - self.args_to_special_window(args, cwd_from=cwd_from), - location=location, allow_remote_control=allow_remote_control) - else: - return tab.new_window(cwd_from=cwd_from, location=location, allow_remote_control=allow_remote_control) + if tab is None: + return None + allow_remote_control = False + location = None + if args and args[0].startswith('!'): + location = args[0][1:].lower() + args = args[1:] + if args and args[0] == '@': + args = args[1:] + allow_remote_control = True + if args: + return tab.new_special_window( + self.args_to_special_window(args, cwd_from=cwd_from), + location=location, allow_remote_control=allow_remote_control) + else: + return tab.new_window(cwd_from=cwd_from, location=location, allow_remote_control=allow_remote_control) @ac('win', 'Create a new window') def new_window(self, *args: str) -> None: diff --git a/kitty/child.py b/kitty/child.py index 17afc79f3..6f96fa438 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -333,6 +333,7 @@ class Child: with suppress(Exception): assert self.pid is not None return cwd_of_process(self.pid) + return None @property def pid_for_cwd(self) -> Optional[int]: @@ -349,6 +350,7 @@ class Child: with suppress(Exception): assert self.pid_for_cwd is not None return cwd_of_process(self.pid_for_cwd) or None + return None @property def foreground_environ(self) -> Dict[str, str]: diff --git a/kitty/file_transmission.py b/kitty/file_transmission.py index cc574dc80..c56eb21d6 100644 --- a/kitty/file_transmission.py +++ b/kitty/file_transmission.py @@ -951,3 +951,4 @@ class TestFileTransmission(FileTransmission): def callback_after(self, callback: Callable[[Optional[int]], None], timeout: float = 0) -> Optional[int]: callback(None) + return None diff --git a/kitty/fonts/box_drawing.py b/kitty/fonts/box_drawing.py index 5c41f12da..5ae81e7af 100644 --- a/kitty/fonts/box_drawing.py +++ b/kitty/fonts/box_drawing.py @@ -10,7 +10,7 @@ import math from functools import partial as p, wraps from itertools import repeat from typing import ( - Any, Callable, Dict, Generator, Iterable, List, MutableSequence, Optional, + Any, Callable, Dict, Iterable, Iterator, List, MutableSequence, Optional, Sequence, Tuple, cast ) @@ -314,6 +314,7 @@ def mid_lines(buf: SSByteArray, width: int, height: int, level: int = 1, pts: It return width - 1, mid_y if p == 'b': return mid_x, height - 1 + raise KeyError(f'Unknown p: {p}') for x in pts: p1, p2 = map(pt_to_coords, x) @@ -353,7 +354,7 @@ def find_bezier_for_D(width: int, height: int) -> int: cx += 1 -def get_bezier_limits(bezier_x: ParameterizedFunc, bezier_y: ParameterizedFunc) -> Generator[Tuple[float, float], None, int]: +def get_bezier_limits(bezier_x: ParameterizedFunc, bezier_y: ParameterizedFunc) -> Iterator[Tuple[float, float]]: start_x = int(bezier_x(0)) max_x = int(bezier_x(0.5)) last_t, t_limit = 0., 0.5 @@ -1043,8 +1044,9 @@ def render_missing_glyph(buf: BufType, width: int, height: int) -> None: def test_char(ch: str, sz: int = 48) -> None: # kitty +runpy "from kitty.fonts.box_drawing import test_char; test_char('XXX')" - from .render import display_bitmap, setup_for_testing from kitty.fast_data_types import concat_cells, set_send_sprite_to_gpu + + from .render import display_bitmap, setup_for_testing with setup_for_testing('monospace', sz) as (_, width, height): buf = bytearray(width * height) try: @@ -1062,9 +1064,10 @@ def test_char(ch: str, sz: int = 48) -> None: def test_drawing(sz: int = 48, family: str = 'monospace', start: int = 0x2500, num_rows: int = 10, num_cols: int = 16) -> None: - from .render import display_bitmap, setup_for_testing from kitty.fast_data_types import concat_cells, set_send_sprite_to_gpu + from .render import display_bitmap, setup_for_testing + with setup_for_testing(family, sz) as (_, width, height): space = bytearray(width * height) diff --git a/kitty/layout/base.py b/kitty/layout/base.py index adcc3fc85..1843c6ae2 100644 --- a/kitty/layout/base.py +++ b/kitty/layout/base.py @@ -69,6 +69,7 @@ def idx_for_id(win_id: int, windows: Iterable[WindowType]) -> Optional[int]: for i, w in enumerate(windows): if w.id == win_id: return i + return None def set_layout_options(opts: Options) -> None: diff --git a/kitty/layout/grid.py b/kitty/layout/grid.py index 1827d017d..022571e95 100644 --- a/kitty/layout/grid.py +++ b/kitty/layout/grid.py @@ -81,6 +81,7 @@ class Grid(Layout): if idx == window_idx: return row_num, col_num row_num += 1 + return 0, 0 row_num, col_num = position_for_window_idx(idx) diff --git a/kitty/layout/splits.py b/kitty/layout/splits.py index 48541dfe5..597af5d46 100644 --- a/kitty/layout/splits.py +++ b/kitty/layout/splits.py @@ -86,6 +86,7 @@ class Pair: for q in root.self_and_descendants(): if q.one is self or q.two is self: return q + return None def remove_windows(self, window_ids: Collection[int]) -> None: if isinstance(self.one, int) and self.one in window_ids: @@ -548,6 +549,7 @@ class Splits(Layout): if swap: pair.one, pair.two = pair.two, pair.one return True + return None def layout_state(self) -> Dict[str, Any]: diff --git a/kitty/layout/tall.py b/kitty/layout/tall.py index d86a7f466..6c5329b14 100644 --- a/kitty/layout/tall.py +++ b/kitty/layout/tall.py @@ -203,6 +203,7 @@ class Tall(Layout): if self.layout_opts.full_size > 1: self.layout_opts.full_size -= 1 return True + return None def minimal_borders(self, all_windows: WindowList) -> Generator[BorderLine, None, None]: num = all_windows.num_groups diff --git a/kitty/notify.py b/kitty/notify.py index eb4d69ff1..93ae9ee45 100644 --- a/kitty/notify.py +++ b/kitty/notify.py @@ -218,3 +218,4 @@ def handle_notification_cmd( cmd = parse_osc_777(raw_data) notify_with_command(cmd, window_id, notify_implementation) return cmd + return None diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 50e5bfd9e..8ab5ca5e6 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -764,7 +764,7 @@ def kitten_alias(val: str) -> Iterable[Tuple[str, List[str]]]: def symbol_map(val: str) -> Iterable[Tuple[Tuple[int, int], str]]: parts = val.split() - def abort() -> Dict[Tuple[int, int], str]: + def abort() -> None: log_error(f'Symbol map: {val} is invalid, ignoring') if len(parts) < 2: diff --git a/kitty/rc/close_tab.py b/kitty/rc/close_tab.py index aaba33333..6a54c82c5 100644 --- a/kitty/rc/close_tab.py +++ b/kitty/rc/close_tab.py @@ -35,6 +35,7 @@ If specified close the tab of the window this command is run in, rather than the for tab in self.tabs_for_match_payload(boss, window, payload_get): if tab: boss.close_tab_no_confirm(tab) + return None close_tab = CloseTab() diff --git a/kitty/rc/close_window.py b/kitty/rc/close_window.py index eccab8c84..8603e8e2f 100644 --- a/kitty/rc/close_window.py +++ b/kitty/rc/close_window.py @@ -34,6 +34,7 @@ If specified close the window this command is run in, rather than the active win for window in self.windows_for_match_payload(boss, window, payload_get): if window: boss.close_window(window) + return None close_window = CloseWindow() diff --git a/kitty/rc/create_marker.py b/kitty/rc/create_marker.py index c2e91e894..56fb3e72c 100644 --- a/kitty/rc/create_marker.py +++ b/kitty/rc/create_marker.py @@ -45,6 +45,7 @@ If specified apply marker to the window this command is run in, rather than the args = payload_get('marker_spec') for window in self.windows_for_match_payload(boss, window, payload_get): window.set_marker(args) + return None create_marker = CreateMarker() diff --git a/kitty/rc/detach_tab.py b/kitty/rc/detach_tab.py index 06dbb05cf..d2b089309 100644 --- a/kitty/rc/detach_tab.py +++ b/kitty/rc/detach_tab.py @@ -57,6 +57,7 @@ If specified detach the tab this command is run in, rather than the active tab. for tab in tabs: boss._move_tab_to(tab=tab, **kwargs) + return None detach_tab = DetachTab() diff --git a/kitty/rc/detach_window.py b/kitty/rc/detach_window.py index 6e1dc8d39..271dfe1c1 100644 --- a/kitty/rc/detach_window.py +++ b/kitty/rc/detach_window.py @@ -53,6 +53,7 @@ If specified detach the window this command is run in, rather than the active wi kwargs = {'target_os_window_id': newval} if target_tab_id is None else {'target_tab_id': target_tab_id} for window in windows: boss._move_window_to(window=window, **kwargs) + return None detach_window = DetachWindow() diff --git a/kitty/rc/disable_ligatures.py b/kitty/rc/disable_ligatures.py index 7e6520c68..2fe35400b 100644 --- a/kitty/rc/disable_ligatures.py +++ b/kitty/rc/disable_ligatures.py @@ -52,6 +52,7 @@ cause ligatures to be changed in all windows. def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: windows = self.windows_for_payload(boss, window, payload_get) boss.disable_ligatures_in(windows, payload_get('strategy')) + return None # }}} diff --git a/kitty/rc/env.py b/kitty/rc/env.py index 4e7bb972c..1b4bc52e8 100644 --- a/kitty/rc/env.py +++ b/kitty/rc/env.py @@ -43,6 +43,7 @@ class Env(RemoteCommand): else: env.pop(k, None) set_default_env(env) + return None env = Env() diff --git a/kitty/rc/focus_tab.py b/kitty/rc/focus_tab.py index 1d6394f5d..054b87cfb 100644 --- a/kitty/rc/focus_tab.py +++ b/kitty/rc/focus_tab.py @@ -41,6 +41,7 @@ using this option means that you will not be notified of failures. if tab: boss.set_active_tab(tab) break + return None focus_tab = FocusTab() diff --git a/kitty/rc/focus_window.py b/kitty/rc/focus_window.py index f6374585c..3392647e3 100644 --- a/kitty/rc/focus_window.py +++ b/kitty/rc/focus_window.py @@ -43,6 +43,7 @@ the command will exit with a success code. if os_window_id: focus_os_window(os_window_id, True) break + return None focus_window = FocusWindow() diff --git a/kitty/rc/goto_layout.py b/kitty/rc/goto_layout.py index 772325a15..df9bbc6e3 100644 --- a/kitty/rc/goto_layout.py +++ b/kitty/rc/goto_layout.py @@ -47,6 +47,7 @@ class GotoLayout(RemoteCommand): tab.goto_layout(payload_get('layout'), raise_exception=True) except ValueError: raise UnknownLayout('The layout {} is unknown or disabled'.format(payload_get('layout'))) + return None goto_layout = GotoLayout() diff --git a/kitty/rc/kitten.py b/kitty/rc/kitten.py index d3ce80e26..f7ed3cd0c 100644 --- a/kitty/rc/kitten.py +++ b/kitty/rc/kitten.py @@ -51,6 +51,7 @@ class Kitten(RemoteCommand): break if isinstance(retval, (str, bool)): return retval + return None kitten = Kitten() diff --git a/kitty/rc/last_used_layout.py b/kitty/rc/last_used_layout.py index ab9697689..a56f46358 100644 --- a/kitty/rc/last_used_layout.py +++ b/kitty/rc/last_used_layout.py @@ -45,6 +45,7 @@ the command will exit with a success code. for tab in self.tabs_for_match_payload(boss, window, payload_get): if tab: tab.last_used_layout() + return None last_used_layout = LastUsedLayout() diff --git a/kitty/rc/remove_marker.py b/kitty/rc/remove_marker.py index 0d61f4277..0915c7110 100644 --- a/kitty/rc/remove_marker.py +++ b/kitty/rc/remove_marker.py @@ -34,6 +34,7 @@ If specified apply marker to the window this command is run in, rather than the def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: for window in self.windows_for_match_payload(boss, window, payload_get): window.remove_marker() + return None remove_marker = RemoveMarker() diff --git a/kitty/rc/resize_os_window.py b/kitty/rc/resize_os_window.py index 8a00ffc79..2dba0f008 100644 --- a/kitty/rc/resize_os_window.py +++ b/kitty/rc/resize_os_window.py @@ -96,6 +96,7 @@ using this option means that you will not be notified of failures. boss.toggle_fullscreen(os_window_id) elif ac == 'toggle-maximized': boss.toggle_maximized(os_window_id) + return None resize_os_window = ResizeOSWindow() diff --git a/kitty/rc/scroll_window.py b/kitty/rc/scroll_window.py index b9d6582d2..a718849a0 100644 --- a/kitty/rc/scroll_window.py +++ b/kitty/rc/scroll_window.py @@ -69,6 +69,7 @@ class ScrollWindow(RemoteCommand): func = getattr(window, f'scroll_{unit}_{direction}') for i in range(abs(amt)): func() + return None scroll_window = ScrollWindow() diff --git a/kitty/rc/send_text.py b/kitty/rc/send_text.py index 5fe1b3b5b..cb9566218 100644 --- a/kitty/rc/send_text.py +++ b/kitty/rc/send_text.py @@ -161,6 +161,7 @@ Do not send text to the active window, even if it is one of the matched windows. window.write_to_child(kdata) else: window.write_to_child(data) + return None send_text = SendText() diff --git a/kitty/rc/set_background_image.py b/kitty/rc/set_background_image.py index f2c263e5c..a8e4da801 100644 --- a/kitty/rc/set_background_image.py +++ b/kitty/rc/set_background_image.py @@ -124,6 +124,7 @@ failed, the command will exit with a success code. except ValueError as err: err.hide_traceback = True # type: ignore raise + return None set_background_image = SetBackgroundImage() diff --git a/kitty/rc/set_background_opacity.py b/kitty/rc/set_background_opacity.py index 263354fc0..e0d0f377d 100644 --- a/kitty/rc/set_background_opacity.py +++ b/kitty/rc/set_background_opacity.py @@ -53,6 +53,7 @@ cause colors to be changed in all windows. windows = self.windows_for_payload(boss, window, payload_get) for os_window_id in {w.os_window_id for w in windows}: boss._set_os_window_background_opacity(os_window_id, payload_get('opacity')) + return None set_background_opacity = SetBackgroundOpacity() diff --git a/kitty/rc/set_colors.py b/kitty/rc/set_colors.py index f05615b2a..dff7fbb64 100644 --- a/kitty/rc/set_colors.py +++ b/kitty/rc/set_colors.py @@ -107,6 +107,7 @@ this option, any color arguments are ignored and --configured and --all are impl if default_bg_changed: boss.default_bg_changed_for(w.id) w.refresh() + return None set_colors = SetColors() diff --git a/kitty/rc/set_enabled_layouts.py b/kitty/rc/set_enabled_layouts.py index 498785e31..96679da42 100644 --- a/kitty/rc/set_enabled_layouts.py +++ b/kitty/rc/set_enabled_layouts.py @@ -64,6 +64,7 @@ as well. for tab in tabs: if tab: tab.set_enabled_layouts(layouts) + return None set_enabled_layouts = SetEnabledLayouts() diff --git a/kitty/rc/set_font_size.py b/kitty/rc/set_font_size.py index 80ff26166..26fa09d64 100644 --- a/kitty/rc/set_font_size.py +++ b/kitty/rc/set_font_size.py @@ -49,6 +49,7 @@ the font size for any newly created OS Windows in the future. boss.change_font_size( payload_get('all'), payload_get('increment_op'), payload_get('size')) + return None set_font_size = SetFontSize() diff --git a/kitty/rc/set_spacing.py b/kitty/rc/set_spacing.py index f77fe0f68..db1700da5 100644 --- a/kitty/rc/set_spacing.py +++ b/kitty/rc/set_spacing.py @@ -119,6 +119,7 @@ windows). for tab in dirtied_tabs.values(): tab.relayout() + return None set_spacing = SetSpacing() diff --git a/kitty/rc/set_tab_color.py b/kitty/rc/set_tab_color.py index 6a1ff9d41..3c22b585a 100644 --- a/kitty/rc/set_tab_color.py +++ b/kitty/rc/set_tab_color.py @@ -76,6 +76,7 @@ If specified close the tab this command is run in, rather than the active tab. for k, v in s.items(): setattr(tab, k, v) tab.mark_tab_bar_dirty() + return None set_tab_color = SetTabColor() diff --git a/kitty/rc/set_tab_title.py b/kitty/rc/set_tab_title.py index 29c8b7b6a..72d0e331b 100644 --- a/kitty/rc/set_tab_title.py +++ b/kitty/rc/set_tab_title.py @@ -37,6 +37,7 @@ class SetTabTitle(RemoteCommand): for tab in self.tabs_for_match_payload(boss, window, payload_get): if tab: tab.set_title(payload_get('title')) + return None set_tab_title = SetTabTitle() diff --git a/kitty/rc/set_window_title.py b/kitty/rc/set_window_title.py index 55a5919c8..31c90d713 100644 --- a/kitty/rc/set_window_title.py +++ b/kitty/rc/set_window_title.py @@ -57,6 +57,7 @@ want to allow other programs to change it afterwards, use this option. window.title_changed(payload_get('title')) else: window.set_title(payload_get('title')) + return None set_window_title = SetWindowTitle() diff --git a/kitty/rc/signal_child.py b/kitty/rc/signal_child.py index d09eec805..40da9e324 100644 --- a/kitty/rc/signal_child.py +++ b/kitty/rc/signal_child.py @@ -47,6 +47,7 @@ class SignalChild(RemoteCommand): for window in windows: if window: window.signal_child(*signals) + return None signal_child = SignalChild() diff --git a/kitty/shell_integration.py b/kitty/shell_integration.py index 2ea4fa778..5f271af24 100644 --- a/kitty/shell_integration.py +++ b/kitty/shell_integration.py @@ -61,7 +61,7 @@ def setup_bash_integration() -> None: setup_integration('bash', os.path.expanduser('~/.bashrc')) -def atomic_symlink(destination: str, in_directory: str) -> str: +def atomic_symlink(destination: str, in_directory: str) -> None: os.makedirs(in_directory, exist_ok=True) name = os.path.basename(destination) tmpname = os.path.join(in_directory, f'{name}-{os.getpid()}-{time.monotonic()}') @@ -97,6 +97,7 @@ def get_supported_shell_name(path: str) -> Optional[str]: name = os.path.basename(path).split('.')[0].lower() if name in SUPPORTED_SHELLS: return name + return None @run_once diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index f89193a0d..bca7542d2 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -578,3 +578,4 @@ class TabBar: for i, (a, b) in enumerate(self.cell_ranges): if a <= x <= b: return i + return None diff --git a/kitty/tabs.py b/kitty/tabs.py index 5788d7256..08019ce6c 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -500,6 +500,7 @@ class Tab: # {{{ def get_nth_window(self, n: int) -> Optional[Window]: if self.windows: return self.current_layout.nth_window(self.windows, n) + return None @ac('win', ''' Focus the nth window if positive or the previously active windows if negative @@ -541,6 +542,7 @@ class Tab: # {{{ if groups: return groups[0] + return None def nth_active_window_id(self, n: int = 0) -> int: if n <= 0: @@ -553,6 +555,7 @@ class Tab: # {{{ candidates = neighbors.get(which) if candidates: return self.most_recent_group(candidates) + return None @ac('win', ''' Focus the neighboring window in the current tab @@ -794,6 +797,7 @@ class TabManager: # {{{ delta = -1 if loc == 'left' else 1 idx = (len(self.tabs) + self.active_tab_idx + delta) % len(self.tabs) return self.tabs[idx] + return None def goto_tab(self, tab_num: int) -> None: if tab_num >= len(self.tabs): @@ -856,6 +860,7 @@ class TabManager: # {{{ t = self.active_tab if t is not None: return t.active_window + return None @property def number_of_windows_with_running_programs(self) -> int: @@ -875,6 +880,7 @@ class TabManager: # {{{ for t in self.tabs: if t.id == tab_id: return t + return None def move_tab(self, delta: int = 1) -> None: if len(self.tabs) > 1: diff --git a/kitty/utils.py b/kitty/utils.py index bac1ee331..21f70d5cb 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -61,6 +61,7 @@ def platform_window_id(os_window_id: int) -> Optional[int]: from .fast_data_types import x11_window_id with suppress(Exception): return x11_window_id(os_window_id) + return None def load_shaders(name: str, vertex_name: str = '', fragment_name: str = '') -> Tuple[str, str]: @@ -284,6 +285,7 @@ def init_startup_notification(window_handle: Optional[int], startup_id: Optional except Exception: import traceback traceback.print_exc() + return None def end_startup_notification(ctx: Optional['StartupCtx']) -> None: @@ -500,6 +502,7 @@ def resolve_editor_cmd(editor: str, shell_env: Mapping[str, str]) -> Optional[st q = shutil.which(editor_exe, path=shell_env['PATH']) if q: return patched(q) + return None def get_editor_from_env(env: Mapping[str, str]) -> Optional[str]: @@ -509,6 +512,7 @@ def get_editor_from_env(env: Mapping[str, str]) -> Optional[str]: editor = resolve_editor_cmd(editor, env) if editor: return editor + return None def get_editor_from_env_vars(opts: Optional[Options] = None) -> List[str]: diff --git a/kitty/window.py b/kitty/window.py index c9ecd2698..9009628e5 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -594,6 +594,7 @@ class Window: if not text: return True self.write_to_child(text) + return False @ac('debug', 'Show a dump of the current lines in the scrollback + screen with their line attributes') def dump_lines_with_attrs(self) -> None: diff --git a/kitty/window_list.py b/kitty/window_list.py index fc67c681f..baf66f4d7 100644 --- a/kitty/window_list.py +++ b/kitty/window_list.py @@ -108,6 +108,7 @@ class WindowGroup: if self.windows: w: WindowType = self.windows[-1] return w.geometry + return None @property def is_visible_in_layout(self) -> bool: @@ -195,6 +196,7 @@ class WindowList: for i, gr in enumerate(self.groups): if gr.id == group_id: return self.set_active_group_idx(i) + return False def change_tab(self, tab: TabType) -> None: self.tabref = weakref.ref(tab) @@ -241,32 +243,38 @@ class WindowList: for g in self.groups: if q in g: return g + return None def group_idx_for_window(self, x: WindowOrId) -> Optional[int]: q = self.id_map[x] if isinstance(x, int) else x for i, g in enumerate(self.groups): if q in g: return i + return None def windows_in_group_of(self, x: WindowOrId) -> Iterator[WindowType]: g = self.group_for_window(x) if g is not None: return iter(g) + return iter(()) @property def active_group(self) -> Optional[WindowGroup]: with suppress(Exception): return self.groups[self.active_group_idx] + return None @property def active_window(self) -> Optional[WindowType]: with suppress(Exception): return self.id_map[self.groups[self.active_group_idx].active_window_id] + return None @property def active_group_base(self) -> Optional[WindowType]: with suppress(Exception): return self.id_map[self.groups[self.active_group_idx].base_window_id] + return None def set_active_window_group_for(self, x: WindowOrId) -> None: try: @@ -350,6 +358,7 @@ class WindowList: n = max(0, min(n, self.num_groups - 1)) if 0 <= n < self.num_groups: return self.id_map.get(self.groups[n].active_window_id) + return None def activate_next_window_group(self, delta: int) -> None: self.set_active_group_idx(wrap_increment(self.active_group_idx, self.num_groups, delta)) diff --git a/setup.cfg b/setup.cfg index 78163de63..17d549162 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,6 @@ warn_redundant_casts = True warn_unused_ignores = True warn_return_any = True warn_unreachable = True -warn_no_return = False warn_unused_configs = True check_untyped_defs = True disallow_untyped_defs = True