Skip to content

Commit 4494ddd

Browse files
committed
mypy: Turn on return value checks
Its a shame GvR is married to "return None" python/mypy#7511
1 parent 5cb36a4 commit 4494ddd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+124
-49
lines changed

kittens/broadcast/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def main(args: List[str]) -> Optional[Dict[str, Any]]:
106106
loop = Loop()
107107
handler = Broadcast(opts, items)
108108
loop.loop(handler)
109+
return None
109110

110111

111112
if __name__ == '__main__':

kittens/diff/patch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def find_differ() -> Optional[str]:
2424
return GIT_DIFF
2525
if shutil.which('diff'):
2626
return DIFF_DIFF
27+
return None
2728

2829

2930
def set_diff_command(opt: str) -> None:

kittens/hints/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ def main(args: List[str]) -> Optional[Dict[str, Any]]:
688688
import traceback
689689
traceback.print_exc()
690690
input(_('Press Enter to quit'))
691+
return None
691692

692693

693694
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:

kittens/remote_file/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def __enter__(self) -> 'ControlMaster':
132132
self.dest = os.path.join(self.tdir, os.path.basename(self.remote_path))
133133
return self
134134

135-
def __exit__(self, *a: Any) -> bool:
135+
def __exit__(self, *a: Any) -> None:
136136
subprocess.Popen(
137137
self.batch_cmd_prefix + ['-O', 'exit', self.conn_data.hostname],
138138
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL
@@ -215,6 +215,7 @@ def main(args: List[str]) -> Result:
215215
import traceback
216216
traceback.print_exc()
217217
show_error('Failed with unhandled exception')
218+
return None
218219

219220

220221
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:
312313
elif action == 'save':
313314
print('Saving', cli_opts.path, 'from', cli_opts.hostname)
314315
save_as(conn_data, remote_path, cli_opts)
316+
return None
315317

316318

317319
@result_handler()

kittens/themes/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def set_colors_to_current_theme(self) -> bool:
203203
col = color_as_sharp(color_from_int(o.color_table[i]))
204204
cmds.append(f'{i};{col}')
205205
self.print(end='\033]4;' + ';'.join(cmds) + '\033\\')
206+
return True
206207

207208
def redraw_after_category_change(self) -> None:
208209
self.themes_list.update_themes(self.all_themes.filtered(self.filter_map[self.current_category]))

kittens/transfer/send.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def active_file(self) -> Optional[File]:
312312
ans = self.files[self.active_idx]
313313
if ans.state is FileState.transmitting:
314314
return ans
315+
return None
315316

316317
def activate_next_ready_file(self) -> Optional[File]:
317318
if self.active_idx is not None:
@@ -325,6 +326,7 @@ def activate_next_ready_file(self) -> Optional[File]:
325326
return f
326327
self.active_idx = None
327328
self.update_collective_statuses()
329+
return None
328330

329331
def update_collective_statuses(self) -> None:
330332
found_not_started = found_not_done = False

kittens/tui/handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def shortcut_action(self, key_event: KeyEventType) -> Optional[KeyActionType]:
8383
for sc, action in self._key_shortcuts.items():
8484
if key_event.matches(sc):
8585
return action
86+
return None
8687

8788
def __enter__(self) -> None:
8889
if self._image_manager is not None:

kittens/tui/path_completer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def __call__(self, text: str, state: int) -> Optional[str]:
132132
options = self.cache[text] = tuple(find_completions(text))
133133
if options and state < len(options):
134134
return options[state]
135+
return None
135136

136137
def __exit__(self, *a: Any) -> bool:
137138
import readline
@@ -143,6 +144,7 @@ def __exit__(self, *a: Any) -> bool:
143144
def input(self) -> str:
144145
with self:
145146
return input(self.prompt)
147+
return ''
146148

147149

148150
def develop() -> None:

kittens/unicode_input/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def __init__(self, emoji_variation: str) -> None:
157157
def current_codepoint(self) -> Optional[int]:
158158
if self.codepoints:
159159
return self.codepoints[self.current_idx]
160+
return None
160161

161162
def set_codepoints(self, codepoints: List[int], mode: str = HEX, current_idx: int = 0) -> None:
162163
self.codepoints = codepoints

kitty/boss.py

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from functools import partial
1010
from gettext import gettext as _
1111
from typing import (
12-
Any, Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union,
13-
cast
12+
Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple,
13+
Union, cast
1414
)
1515
from weakref import WeakValueDictionary
1616

@@ -27,16 +27,16 @@
2727
)
2828
from .fast_data_types import (
2929
CLOSE_BEING_CONFIRMED, GLFW_MOD_ALT, GLFW_MOD_CONTROL, GLFW_MOD_SHIFT,
30-
GLFW_MOD_SUPER, IMPERATIVE_CLOSE_REQUESTED, NO_CLOSE_REQUESTED,
31-
ChildMonitor, KeyEvent, add_timer, apply_options_update,
32-
background_opacity_of, change_background_opacity, change_os_window_state,
33-
cocoa_set_menubar_title, create_os_window, GLFW_PRESS, GLFW_MOUSE_BUTTON_LEFT,
34-
current_application_quit_request, current_os_window, destroy_global_data,
35-
focus_os_window, get_clipboard_string, get_options, get_os_window_size,
36-
global_font_size, mark_os_window_for_close, os_window_font_size,
37-
patch_global_colors, redirect_mouse_handling, ring_bell, safe_pipe,
38-
set_application_quit_request, set_background_image, set_boss,
39-
set_clipboard_string, set_in_sequence_mode, set_options,
30+
GLFW_MOD_SUPER, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS,
31+
IMPERATIVE_CLOSE_REQUESTED, NO_CLOSE_REQUESTED, ChildMonitor, KeyEvent,
32+
add_timer, apply_options_update, background_opacity_of,
33+
change_background_opacity, change_os_window_state, cocoa_set_menubar_title,
34+
create_os_window, current_application_quit_request, current_os_window,
35+
destroy_global_data, focus_os_window, get_clipboard_string, get_options,
36+
get_os_window_size, global_font_size, mark_os_window_for_close,
37+
os_window_font_size, patch_global_colors, redirect_mouse_handling,
38+
ring_bell, safe_pipe, set_application_quit_request, set_background_image,
39+
set_boss, set_clipboard_string, set_in_sequence_mode, set_options,
4040
set_os_window_size, thread_write, toggle_fullscreen, toggle_maximized
4141
)
4242
from .key_encoding import get_name_to_functional_number_map
@@ -234,7 +234,7 @@ def add_os_window(
234234
self.os_window_map[os_window_id] = tm
235235
return os_window_id
236236

237-
def list_os_windows(self, self_window: Optional[Window] = None) -> Generator[OSWindowDict, None, None]:
237+
def list_os_windows(self, self_window: Optional[Window] = None) -> Iterator[OSWindowDict]:
238238
with cached_process_data():
239239
active_tab, active_window = self.active_tab, self.active_window
240240
active_tab_manager = self.active_tab_manager
@@ -249,20 +249,20 @@ def list_os_windows(self, self_window: Optional[Window] = None) -> Generator[OSW
249249
}
250250

251251
@property
252-
def all_tab_managers(self) -> Generator[TabManager, None, None]:
252+
def all_tab_managers(self) -> Iterator[TabManager]:
253253
yield from self.os_window_map.values()
254254

255255
@property
256-
def all_tabs(self) -> Generator[Tab, None, None]:
256+
def all_tabs(self) -> Iterator[Tab]:
257257
for tm in self.all_tab_managers:
258258
yield from tm
259259

260260
@property
261-
def all_windows(self) -> Generator[Window, None, None]:
261+
def all_windows(self) -> Iterator[Window]:
262262
for tab in self.all_tabs:
263263
yield from tab
264264

265-
def match_windows(self, match: str) -> Generator[Window, None, None]:
265+
def match_windows(self, match: str) -> Iterator[Window]:
266266
try:
267267
field, exp = match.split(':', 1)
268268
except ValueError:
@@ -305,8 +305,9 @@ def tab_for_window(self, window: Window) -> Optional[Tab]:
305305
for w in tab:
306306
if w.id == window.id:
307307
return tab
308+
return None
308309

309-
def match_tabs(self, match: str) -> Generator[Tab, None, None]:
310+
def match_tabs(self, match: str) -> Iterator[Tab]:
310311
try:
311312
field, exp = match.split(':', 1)
312313
except ValueError:
@@ -359,6 +360,7 @@ def set_active_window(self, window: Window, switch_os_window_if_needed: bool = F
359360
if switch_os_window_if_needed and current_os_window() != os_window_id:
360361
focus_os_window(os_window_id, True)
361362
return os_window_id
363+
return None
362364

363365
def _new_os_window(self, args: Union[SpecialWindowInstance, Iterable[str]], cwd_from: Optional[int] = None) -> int:
364366
if isinstance(args, SpecialWindowInstance):
@@ -377,6 +379,7 @@ def active_window_for_cwd(self) -> Optional[Window]:
377379
t = self.active_tab
378380
if t is not None:
379381
return t.active_window_for_cwd
382+
return None
380383

381384
@ac('win', 'New OS Window with the same working directory as the currently active window')
382385
def new_os_window_with_cwd(self, *args: str) -> None:
@@ -595,7 +598,7 @@ def start(self, first_os_window_id: int) -> None:
595598
run_update_check(get_options().update_check_interval * 60 * 60)
596599
self.update_check_started = True
597600

598-
def handle_click_on_tab(self, os_window_id: int, x: int, button: int, modifiers: int, action: int) -> int:
601+
def handle_click_on_tab(self, os_window_id: int, x: int, button: int, modifiers: int, action: int) -> None:
599602
tm = self.os_window_map.get(os_window_id)
600603
if tm is not None:
601604
tm.handle_click_on_tab(x, button, modifiers, action)
@@ -751,20 +754,17 @@ def set_background_opacity(self, opacity: str) -> None:
751754
@property
752755
def active_tab_manager(self) -> Optional[TabManager]:
753756
os_window_id = current_os_window()
754-
if os_window_id is not None:
755-
return self.os_window_map.get(os_window_id)
757+
return None if os_window_id is None else self.os_window_map.get(os_window_id)
756758

757759
@property
758760
def active_tab(self) -> Optional[Tab]:
759761
tm = self.active_tab_manager
760-
if tm is not None:
761-
return tm.active_tab
762+
return None if tm is None else tm.active_tab
762763

763764
@property
764765
def active_window(self) -> Optional[Window]:
765766
t = self.active_tab
766-
if t is not None:
767-
return t.active_window
767+
return None if t is None else t.active_window
768768

769769
def set_pending_sequences(self, sequences: SubSequenceMap, default_pending_action: Optional[KeyAction] = None) -> None:
770770
self.pending_sequences = sequences
@@ -783,6 +783,7 @@ def dispatch_possible_special_key(self, ev: KeyEvent) -> bool:
783783
return True
784784
elif isinstance(key_action, KeyAction):
785785
return self.dispatch_action(key_action)
786+
return False
786787

787788
def clear_pending_sequences(self) -> None:
788789
self.pending_sequences = self.default_pending_action = None
@@ -1530,7 +1531,7 @@ def run_background_process(
15301531
else:
15311532
subprocess.Popen(cmd, env=env, cwd=cwd)
15321533

1533-
def pipe(self, source: str, dest: str, exe: str, *args: str) -> Window:
1534+
def pipe(self, source: str, dest: str, exe: str, *args: str) -> Optional[Window]:
15341535
cmd = [exe] + list(args)
15351536
window = self.active_window
15361537
cwd_from = window.child.pid_for_cwd if window else None
@@ -1559,6 +1560,7 @@ def create_window() -> SpecialWindowInstance:
15591560
else:
15601561
env, stdin = self.process_stdin_source(stdin=source, window=window)
15611562
self.run_background_process(cmd, cwd_from=cwd_from, stdin=stdin, env=env)
1563+
return None
15621564

15631565
def args_to_special_window(self, args: Iterable[str], cwd_from: Optional[int] = None) -> SpecialWindowInstance:
15641566
args = list(args)
@@ -1591,6 +1593,7 @@ def _new_tab(self, args: Union[SpecialWindowInstance, Iterable[str]], cwd_from:
15911593
tm = self.active_tab_manager
15921594
if tm is not None:
15931595
return tm.new_tab(special_window=special_window, cwd_from=cwd_from, as_neighbor=as_neighbor)
1596+
return None
15941597

15951598
def _create_tab(self, args: List[str], cwd_from: Optional[int] = None) -> None:
15961599
as_neighbor = False
@@ -1615,21 +1618,22 @@ def new_tab_with_wd(self, wd: str) -> None:
16151618

16161619
def _new_window(self, args: List[str], cwd_from: Optional[int] = None) -> Optional[Window]:
16171620
tab = self.active_tab
1618-
if tab is not None:
1619-
allow_remote_control = False
1620-
location = None
1621-
if args and args[0].startswith('!'):
1622-
location = args[0][1:].lower()
1623-
args = args[1:]
1624-
if args and args[0] == '@':
1625-
args = args[1:]
1626-
allow_remote_control = True
1627-
if args:
1628-
return tab.new_special_window(
1629-
self.args_to_special_window(args, cwd_from=cwd_from),
1630-
location=location, allow_remote_control=allow_remote_control)
1631-
else:
1632-
return tab.new_window(cwd_from=cwd_from, location=location, allow_remote_control=allow_remote_control)
1621+
if tab is None:
1622+
return None
1623+
allow_remote_control = False
1624+
location = None
1625+
if args and args[0].startswith('!'):
1626+
location = args[0][1:].lower()
1627+
args = args[1:]
1628+
if args and args[0] == '@':
1629+
args = args[1:]
1630+
allow_remote_control = True
1631+
if args:
1632+
return tab.new_special_window(
1633+
self.args_to_special_window(args, cwd_from=cwd_from),
1634+
location=location, allow_remote_control=allow_remote_control)
1635+
else:
1636+
return tab.new_window(cwd_from=cwd_from, location=location, allow_remote_control=allow_remote_control)
16331637

16341638
@ac('win', 'Create a new window')
16351639
def new_window(self, *args: str) -> None:

kitty/child.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ def current_cwd(self) -> Optional[str]:
333333
with suppress(Exception):
334334
assert self.pid is not None
335335
return cwd_of_process(self.pid)
336+
return None
336337

337338
@property
338339
def pid_for_cwd(self) -> Optional[int]:
@@ -349,6 +350,7 @@ def foreground_cwd(self) -> Optional[str]:
349350
with suppress(Exception):
350351
assert self.pid_for_cwd is not None
351352
return cwd_of_process(self.pid_for_cwd) or None
353+
return None
352354

353355
@property
354356
def foreground_environ(self) -> Dict[str, str]:

kitty/file_transmission.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,4 @@ def start_send(self, aid: str) -> None:
951951

952952
def callback_after(self, callback: Callable[[Optional[int]], None], timeout: float = 0) -> Optional[int]:
953953
callback(None)
954+
return None

kitty/fonts/box_drawing.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from functools import partial as p, wraps
1111
from itertools import repeat
1212
from typing import (
13-
Any, Callable, Dict, Generator, Iterable, List, MutableSequence, Optional,
13+
Any, Callable, Dict, Iterable, Iterator, List, MutableSequence, Optional,
1414
Sequence, Tuple, cast
1515
)
1616

@@ -314,6 +314,7 @@ def pt_to_coords(p: str) -> Tuple[int, int]:
314314
return width - 1, mid_y
315315
if p == 'b':
316316
return mid_x, height - 1
317+
raise KeyError(f'Unknown p: {p}')
317318

318319
for x in pts:
319320
p1, p2 = map(pt_to_coords, x)
@@ -353,7 +354,7 @@ def find_bezier_for_D(width: int, height: int) -> int:
353354
cx += 1
354355

355356

356-
def get_bezier_limits(bezier_x: ParameterizedFunc, bezier_y: ParameterizedFunc) -> Generator[Tuple[float, float], None, int]:
357+
def get_bezier_limits(bezier_x: ParameterizedFunc, bezier_y: ParameterizedFunc) -> Iterator[Tuple[float, float]]:
357358
start_x = int(bezier_x(0))
358359
max_x = int(bezier_x(0.5))
359360
last_t, t_limit = 0., 0.5
@@ -1043,8 +1044,9 @@ def render_missing_glyph(buf: BufType, width: int, height: int) -> None:
10431044

10441045
def test_char(ch: str, sz: int = 48) -> None:
10451046
# kitty +runpy "from kitty.fonts.box_drawing import test_char; test_char('XXX')"
1046-
from .render import display_bitmap, setup_for_testing
10471047
from kitty.fast_data_types import concat_cells, set_send_sprite_to_gpu
1048+
1049+
from .render import display_bitmap, setup_for_testing
10481050
with setup_for_testing('monospace', sz) as (_, width, height):
10491051
buf = bytearray(width * height)
10501052
try:
@@ -1062,9 +1064,10 @@ def join_cells(*cells: bytes) -> bytes:
10621064

10631065

10641066
def test_drawing(sz: int = 48, family: str = 'monospace', start: int = 0x2500, num_rows: int = 10, num_cols: int = 16) -> None:
1065-
from .render import display_bitmap, setup_for_testing
10661067
from kitty.fast_data_types import concat_cells, set_send_sprite_to_gpu
10671068

1069+
from .render import display_bitmap, setup_for_testing
1070+
10681071
with setup_for_testing(family, sz) as (_, width, height):
10691072
space = bytearray(width * height)
10701073

kitty/layout/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def idx_for_id(win_id: int, windows: Iterable[WindowType]) -> Optional[int]:
6969
for i, w in enumerate(windows):
7070
if w.id == win_id:
7171
return i
72+
return None
7273

7374

7475
def set_layout_options(opts: Options) -> None:

kitty/layout/grid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def on_col_done(col_windows: List[int]) -> None:
8181
if idx == window_idx:
8282
return row_num, col_num
8383
row_num += 1
84+
return 0, 0
8485

8586
row_num, col_num = position_for_window_idx(idx)
8687

0 commit comments

Comments
 (0)