From a3ebb2a737b45ba784ff80d8312baf0258516fc5 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sun, 1 Sep 2024 16:00:52 +0200 Subject: [PATCH 1/2] Fix new mypy errors These all point to code-smells I cannot fix quickly enough. --- core/commands/blame.py | 6 ++--- core/commands/checkout.py | 2 +- core/commands/cherry_pick.py | 2 +- core/commands/fixup.py | 8 +++---- core/commands/log.py | 8 +++---- core/commands/log_graph.py | 28 ++++++++++++++--------- core/commands/log_graph_rebase_actions.py | 4 ++-- core/commands/show_file_at_commit.py | 2 +- 8 files changed, 33 insertions(+), 27 deletions(-) diff --git a/core/commands/blame.py b/core/commands/blame.py index 1b0d6cd09..df0378044 100644 --- a/core/commands/blame.py +++ b/core/commands/blame.py @@ -126,7 +126,7 @@ class gs_blame_current_file(LogMixin, GsTextCommand): _commit_hash = None _file_path = None - def run(self, edit, **kwargs): + def run(self, edit, **kwargs): # type: ignore[override] # reset memorized commit hash when blaming a different file if self._file_path != self.file_path: self._commit_hash = None @@ -145,10 +145,10 @@ def do_action(self, commit_hash, **kwargs): "commit_hash": commit_hash, "file_path": self._file_path }) - def selected_index(self, commit_hash): + def selected_index(self, commit_hash): # type: ignore[override] return self._commit_hash == commit_hash - def log(self, **kwargs): + def log(self, **kwargs): # type: ignore[override] follow = self.savvy_settings.get("blame_follow_rename") kwargs["follow"] = follow return super().log(**kwargs) diff --git a/core/commands/checkout.py b/core/commands/checkout.py index cc167ea75..1c03e1574 100644 --- a/core/commands/checkout.py +++ b/core/commands/checkout.py @@ -165,7 +165,7 @@ class gs_checkout_current_file_at_commit(LogMixin, WindowCommand, GitCommand): Reset the current active file to a given commit. """ - def run(self): + def run(self): # type: ignore[override] if self.file_path: super().run(file_path=self.file_path) diff --git a/core/commands/cherry_pick.py b/core/commands/cherry_pick.py index f7ca1ec3d..b1b9233bf 100644 --- a/core/commands/cherry_pick.py +++ b/core/commands/cherry_pick.py @@ -16,7 +16,7 @@ class gs_cherry_pick(gs_log_by_branch): - def log(self, **kwargs): + def log(self, **kwargs): # type: ignore[override] kwargs["cherry"] = True kwargs["start_end"] = ("", kwargs["branch"]) return super().log(**kwargs) diff --git a/core/commands/fixup.py b/core/commands/fixup.py index 9168e941e..a84d045ff 100644 --- a/core/commands/fixup.py +++ b/core/commands/fixup.py @@ -7,7 +7,7 @@ class GsFixupFromStageCommand(gs_log_current_branch): - def run(self): + def run(self): # type: ignore[override] status = self.get_working_dir_status() if status.unstaged_files or status.merge_conflicts: sublime.message_dialog( @@ -43,8 +43,8 @@ def auto_squash(self, commit_chain): return commit_chain - def do_action(self, commit, **kwargs): - commit = self.git("rev-parse", commit).strip() + def do_action(self, commit_hash, **kwargs): + commit = self.git("rev-parse", commit_hash).strip() self.git("commit", "--fixup", commit) try: base_commit = self.git("rev-parse", "{}~1".format(commit)).strip() @@ -61,6 +61,6 @@ def do_action(self, commit, **kwargs): class GsQuickStageCurrentFileAndFixupCommand(GsFixupFromStageCommand): - def run(self): + def run(self): # type: ignore[override] self.git("add", "--", self.file_path) super().run() diff --git a/core/commands/log.py b/core/commands/log.py index 474564a5d..64d997be2 100644 --- a/core/commands/log.py +++ b/core/commands/log.py @@ -39,13 +39,13 @@ class LogMixin(GitCommand): selected_index: Union[int, Callable[[str], bool]] = 0 - def run(self, *args, commit_hash=None, file_path=None, **kwargs): + def run(self, *, commit_hash=None, file_path=None, **kwargs): if commit_hash: self.do_action(commit_hash, file_path=file_path, **kwargs) else: sublime.set_timeout_async(lambda: self.run_async(file_path=file_path, **kwargs)) - def run_async(self, file_path=None, **kwargs): + def run_async(self, *, file_path=None, **kwargs): follow = self.savvy_settings.get("log_follow_rename") if file_path else False entries = self.log_generator(file_path=file_path, follow=follow, **kwargs) # `on_highlight` gets called on `on_done` as well with the same @@ -119,7 +119,7 @@ class gs_log_current_branch(LogMixin, WindowCommand, GitCommand): class gs_log_all_branches(LogMixin, WindowCommand, GitCommand): - def log(self, **kwargs): + def log(self, **kwargs): # type: ignore[override] return super().log(all_branches=True, **kwargs) @@ -163,7 +163,7 @@ def on_author_selection(self, index, **kwargs): self._selected_author = self._entries[index][3] super().run_async(**kwargs) - def log(self, **kwargs): + def log(self, **kwargs): # type: ignore[override] return super().log(author=self._selected_author, **kwargs) diff --git a/core/commands/log_graph.py b/core/commands/log_graph.py index 29c192bc6..988abf036 100644 --- a/core/commands/log_graph.py +++ b/core/commands/log_graph.py @@ -1176,13 +1176,19 @@ def drain_and_draw_queue(view, painter_state, follow, col_range, visible_selecti col_range, visible_selection, ) - try_navigate_to_symbol = partial( - navigate_to_symbol, - view, - follow, - col_range=col_range, - method=set_and_show_cursor if visible_selection else just_set_cursor - ) + + if not follow: + def try_navigate_to_symbol(*, if_before=None) -> bool: + return False + else: + try_navigate_to_symbol = partial( + navigate_to_symbol, + view, + follow, + col_range=col_range, + method=set_and_show_cursor if visible_selection else just_set_cursor + ) + block_time = utils.timer() while True: # If only the head commits changed, and the cursor (and with it `follow`) @@ -1224,7 +1230,7 @@ def drain_and_draw_queue(view, painter_state, follow, col_range, visible_selecti # If we still did not navigate the symbol is either # gone, or happens to be after the fold of fresh # content. - if not follow or not try_navigate_to_symbol(): + if not try_navigate_to_symbol(): if initial_draw: view.run_command("gs_log_graph_navigate") elif visible_selection: @@ -3114,13 +3120,13 @@ def get_list(info, key): ] return actions - def pull(self): + def pull(self): # type: ignore[override] self.window.run_command("gs_pull") - def push(self, current_branch): + def push(self, current_branch): # type: ignore[override] self.window.run_command("gs_push", {"local_branch_name": current_branch}) - def fetch(self, current_branch): + def fetch(self, current_branch): # type: ignore[override] remote = self.get_remote_for_branch(current_branch) self.window.run_command("gs_fetch", {"remote": remote} if remote else None) diff --git a/core/commands/log_graph_rebase_actions.py b/core/commands/log_graph_rebase_actions.py index 4b829fd5f..5b32fe29e 100644 --- a/core/commands/log_graph_rebase_actions.py +++ b/core/commands/log_graph_rebase_actions.py @@ -1014,13 +1014,13 @@ class gs_rebase_reword_commit(gs_rebase_quick_action): class gs_rebase_apply_fixup(gs_rebase_quick_action): - def run(self, edit, base_commit, fixes): + def run(self, edit, base_commit, fixes): # type: ignore[override] self.action = partial(fixup_commits, [Commit(*fix) for fix in fixes]) super().run(edit, base_commit) class gs_rebase_squash_commits(gs_rebase_quick_action): - def run(self, edit, base_commit, commits): + def run(self, edit, base_commit, commits): # type: ignore[override] self.action = partial(squash_commits, commits) super().run(edit, base_commit) diff --git a/core/commands/show_file_at_commit.py b/core/commands/show_file_at_commit.py index 654c8d9da..11163bc76 100644 --- a/core/commands/show_file_at_commit.py +++ b/core/commands/show_file_at_commit.py @@ -406,7 +406,7 @@ def do_action(self, commit_hash, **kwargs): "lang": view.settings().get('syntax') }) - def selected_index(self, commit_hash): + def selected_index(self, commit_hash): # type: ignore[override] if not self.overlay_for_show_file_at_commit: return True From 45e5bec6ed367bb7c3864e9fdd610c2701ce87ac Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sun, 1 Sep 2024 16:02:04 +0200 Subject: [PATCH 2/2] Ignore mypy errors These look like errors on the mypy side, namely on their `partial`-plugin. --- core/interfaces/rebase.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/interfaces/rebase.py b/core/interfaces/rebase.py index c607660ac..e3b55cf88 100644 --- a/core/interfaces/rebase.py +++ b/core/interfaces/rebase.py @@ -596,7 +596,7 @@ def run_async(self): self.do_action(self.interface.entries[squash_idx - 1].long_hash) else: reversed_logs = list(reversed(self.interface.entries[0:squash_idx])) - show_log_panel(reversed_logs, partial(enqueue_on_worker, self.do_action)) + show_log_panel(reversed_logs, partial(enqueue_on_worker, self.do_action)) # type: ignore[call-arg] def do_action(self, target_commit): if not target_commit: @@ -733,7 +733,7 @@ def run_async(self): self.do_action(self.interface.entries[move_idx - 1].long_hash) else: logs = list(reversed(self.interface.entries[:move_idx])) - show_log_panel(logs, partial(enqueue_on_worker, self.do_action)) + show_log_panel(logs, partial(enqueue_on_worker, self.do_action)) # type: ignore[call-arg] def do_action(self, target_commit): if not target_commit: @@ -785,7 +785,7 @@ def run_async(self): self.do_action(self.interface.entries[move_idx + 1].long_hash) else: logs = self.interface.entries[move_idx + 1:] - show_log_panel(logs, partial(enqueue_on_worker, self.do_action)) + show_log_panel(logs, partial(enqueue_on_worker, self.do_action)) # type: ignore[call-arg] def do_action(self, target_commit): if not target_commit: