Correct a few type definitions in layout.py

This commit is contained in:
Kovid Goyal 2020-03-13 16:21:36 +05:30
parent 917559f883
commit 5414dc398e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 10 deletions

View File

@ -3,7 +3,7 @@
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from itertools import chain from itertools import chain
from typing import TYPE_CHECKING, Optional, Sequence, Tuple from typing import TYPE_CHECKING, List, Optional, Sequence, Tuple
from .constants import WindowGeometry from .constants import WindowGeometry
from .fast_data_types import ( from .fast_data_types import (
@ -63,7 +63,7 @@ class Borders:
def __call__( def __call__(
self, self,
windows: Sequence['Window'], windows: List['Window'],
active_window: Optional['Window'], active_window: Optional['Window'],
current_layout: 'Layout', current_layout: 'Layout',
extra_blank_rects: Sequence[Tuple[int, int, int, int]], extra_blank_rects: Sequence[Tuple[int, int, int, int]],

View File

@ -546,21 +546,21 @@ class Layout: # {{{
def neighbors_for_window(self, window: Window, windows: WindowList) -> InternalNeighborsMap: def neighbors_for_window(self, window: Window, windows: WindowList) -> InternalNeighborsMap:
return {'left': [], 'right': [], 'top': [], 'bottom': []} return {'left': [], 'right': [], 'top': [], 'bottom': []}
def compute_needs_borders_map(self, windows: WindowList, active_window: Window) -> Dict[int, bool]: def compute_needs_borders_map(self, windows: WindowList, active_window: Optional[Window]) -> Dict[int, bool]:
return {w.id: ((w is active_window and draw_active_borders) or w.needs_attention) for w in windows} return {w.id: ((w is active_window and draw_active_borders) or w.needs_attention) for w in windows}
def resolve_borders(self, windows: WindowList, active_window: Window) -> Generator[Borders, None, None]: def resolve_borders(self, windows: WindowList, active_window: Optional[Window]) -> Generator[Borders, None, None]:
if draw_minimal_borders: if draw_minimal_borders:
needs_borders_map = self.compute_needs_borders_map(windows, active_window) needs_borders_map = self.compute_needs_borders_map(windows, active_window)
yield from self.minimal_borders(windows, active_window, needs_borders_map) yield from self.minimal_borders(windows, active_window, needs_borders_map)
else: else:
yield from Layout.minimal_borders(self, windows, active_window, {}) yield from Layout.minimal_borders(self, windows, active_window, {})
def window_independent_borders(self, windows: WindowList, active_windows: WindowList) -> Generator[Tuple[int, int, int, int], None, None]: def window_independent_borders(self, windows: WindowList, active_window: Optional[Window] = None) -> Generator[Tuple[int, int, int, int], None, None]:
return return
yield (0, 0, 0, 0) # type: ignore yield (0, 0, 0, 0) # type: ignore
def minimal_borders(self, windows: WindowList, active_window: Window, needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]: def minimal_borders(self, windows: WindowList, active_window: Optional[Window], needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]:
for w in windows: for w in windows:
if (w is active_window and draw_active_borders) or w.needs_attention: if (w is active_window and draw_active_borders) or w.needs_attention:
yield all_borders yield all_borders
@ -716,7 +716,7 @@ class Tall(Layout):
def neighbors_for_window(self, window: Window, windows: WindowList) -> InternalNeighborsMap: def neighbors_for_window(self, window: Window, windows: WindowList) -> InternalNeighborsMap:
return neighbors_for_tall_window(self.num_full_size_windows, window, windows) return neighbors_for_tall_window(self.num_full_size_windows, window, windows)
def minimal_borders(self, windows: WindowList, active_window: Window, needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]: def minimal_borders(self, windows: WindowList, active_window: Optional[Window], needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]:
last_i = len(windows) - 1 last_i = len(windows) - 1
for i, w in enumerate(windows): for i, w in enumerate(windows):
if needs_borders_map[w.id]: if needs_borders_map[w.id]:
@ -925,7 +925,7 @@ class Grid(Layout):
for i in range(ncols - 1): for i in range(ncols - 1):
self.between_blank_rect(win_col_map[i][0], win_col_map[i + 1][0]) self.between_blank_rect(win_col_map[i][0], win_col_map[i + 1][0])
def minimal_borders(self, windows: WindowList, active_window: Window, needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]: def minimal_borders(self, windows: WindowList, active_window: Optional[Window], needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]:
n = len(windows) n = len(windows)
ncols, nrows, special_rows, special_col = calc_grid_size(n) ncols, nrows, special_rows, special_col = calc_grid_size(n)
blank_row: List[Optional[int]] = [None for i in range(ncols)] blank_row: List[Optional[int]] = [None for i in range(ncols)]
@ -1051,7 +1051,7 @@ class Vertical(Layout): # {{{
# left, top and right blank rects # left, top and right blank rects
self.simple_blank_rects(windows[0], windows[-1]) self.simple_blank_rects(windows[0], windows[-1])
def minimal_borders(self, windows: WindowList, active_window: Window, needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]: def minimal_borders(self, windows: WindowList, active_window: Optional[Window], needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]:
last_i = len(windows) - 1 last_i = len(windows) - 1
for i, w in enumerate(windows): for i, w in enumerate(windows):
if needs_borders_map[w.id]: if needs_borders_map[w.id]:
@ -1490,7 +1490,7 @@ class Splits(Layout):
pair.bias = 0.5 pair.bias = 0.5
return True return True
def window_independent_borders(self, windows: WindowList, active_windows: WindowList) -> Generator[Tuple[int, int, int, int], None, None]: def window_independent_borders(self, windows: WindowList, active_window: Optional[Window] = None) -> Generator[Tuple[int, int, int, int], None, None]:
if not draw_minimal_borders: if not draw_minimal_borders:
return return
for pair in self.pairs_root.self_and_descendants(): for pair in self.pairs_root.self_and_descendants():