diff --git a/kitty/conf/definition.py b/kitty/conf/definition.py index 9d166c151..4254bf43d 100644 --- a/kitty/conf/definition.py +++ b/kitty/conf/definition.py @@ -332,7 +332,7 @@ def as_type_stub( ans.insert(0, 'import {}'.format(mod)) for field_name, type_def in extra_fields: ans.append(' {}: {}'.format(field_name, type_def)) - ans.append(' def __iter__(self) -> None: pass') + ans.append(' def __iter__(self) -> typing.Iterator[str]: pass') ans.append(' def __len__(self) -> int: pass') ans.append(' def _replace(self, **kw: typing.Any) -> {}: pass'.format(class_name)) return '\n'.join(ans) + '\n\n\n' diff --git a/kitty/layout.py b/kitty/layout.py index 4ea9c4c22..9032bea49 100644 --- a/kitty/layout.py +++ b/kitty/layout.py @@ -5,8 +5,8 @@ from functools import lru_cache, partial from itertools import islice, repeat from typing import ( - TYPE_CHECKING, Callable, Collection, Dict, FrozenSet, Generator, Iterable, - List, NamedTuple, Optional, Sequence, Tuple, Union, cast + TYPE_CHECKING, Callable, Collection, Deque, Dict, FrozenSet, Generator, + Iterable, List, NamedTuple, Optional, Sequence, Tuple, Union, cast ) from .constants import WindowGeometry @@ -53,7 +53,7 @@ draw_active_borders = True align_top_left = False LayoutDimension = Generator[Tuple[int, int], None, None] DecorationPairs = Sequence[Tuple[int, int]] -WindowList = List[Window] +WindowList = Union[List[Window], Deque[Window]] class InternalNeighborsMap(TypedDict): @@ -134,7 +134,7 @@ class Rect(NamedTuple): bottom: int -def process_overlaid_windows(all_windows: WindowList) -> Tuple[FrozenSet[Window], List[Window]]: +def process_overlaid_windows(all_windows: WindowList) -> Tuple[FrozenSet[Window], WindowList]: id_map = {w.id: w for w in all_windows} overlaid_windows = frozenset(w for w in all_windows if w.overlay_window_id is not None and w.overlay_window_id in id_map) windows = [w for w in all_windows if w not in overlaid_windows] @@ -567,8 +567,8 @@ class Layout: # {{{ else: yield no_borders - def layout_action(self, action_name: str, args: Sequence[str], all_windows: WindowList, active_window_idx: int) -> bool: - return False + def layout_action(self, action_name: str, args: Sequence[str], all_windows: WindowList, active_window_idx: int) -> Optional[Union[bool, int]]: + pass # }}} @@ -970,8 +970,8 @@ class Grid(Layout): blank_row: List[Optional[int]] = [None for i in range(ncols)] matrix = tuple(blank_row[:] for j in range(max(nrows, special_rows))) wi = iter(windows) - pos_map = {} - col_counts = [] + pos_map: Dict[int, Tuple[int, int]] = {} + col_counts: List[int] = [] for col in range(ncols): rows = special_rows if col == special_col else nrows for row in range(rows): @@ -1525,7 +1525,7 @@ class Splits(Layout): else: p2.two = w1 - def layout_action(self, action_name: str, args: Sequence[str], all_windows: WindowList, active_window_idx: int) -> bool: + def layout_action(self, action_name: str, args: Sequence[str], all_windows: WindowList, active_window_idx: int) -> Optional[Union[bool, int]]: if action_name == 'rotate': args = args or ('90',) try: @@ -1545,7 +1545,6 @@ class Splits(Layout): if swap: pair.one, pair.two = pair.two, pair.one return True - return False # }}} diff --git a/kitty/tabs.py b/kitty/tabs.py index 4bc7a9c7d..cbcd99ebe 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -87,8 +87,8 @@ class Tab: # {{{ ): self._active_window_idx = 0 self.tab_manager_ref = weakref.ref(tab_manager) - self.os_window_id = tab_manager.os_window_id - self.id = add_tab(self.os_window_id) + self.os_window_id: int = tab_manager.os_window_id + self.id: int = add_tab(self.os_window_id) self.active_window_history: Deque[int] = deque() if not self.id: raise Exception('No OS window with id {} found, or tab counter has wrapped'.format(self.os_window_id)) @@ -301,7 +301,7 @@ class Tab: # {{{ if ret is None: ring_bell() return - if isinstance(ret, int) and not isinstance(ret, bool): + if not isinstance(ret, bool) and isinstance(ret, int): self.active_window_idx = ret self.relayout() @@ -415,7 +415,7 @@ class Tab: # {{{ active_window_idx = idx next_window_id = q.id break - if next_window_id is None and active_window_idx is not None and len(self.windows) > active_window_idx: + if next_window_id is None and len(self.windows) > active_window_idx: next_window_id = self.windows[active_window_idx].id if next_window_id is not None: for idx, window in enumerate(self.windows):